[XForms] Use pseudoclasses instead of attributes. Bug 271720, r=aaronr+doronr

git-svn-id: svn://10.0.0.236/trunk@182525 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
allan%beaufour.dk 2005-10-19 07:39:36 +00:00
parent 85e3e7e989
commit dd1d312381
5 changed files with 32 additions and 59 deletions

View File

@ -57,6 +57,7 @@
#include "nsIServiceManager.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsIEventStateManager.h"
/** This class is used to generate xforms-hint and xforms-help events.*/
class nsXFormsHintHelpListener : public nsIDOMEventListener {
@ -179,12 +180,10 @@ nsXFormsControlStubBase::ResetBoundNode(const nsString &aBindAttribute,
// doesn't exist in the instance document. Disable the control
// per 4.2.2 in the spec
// Set pseudo class
///
/// @bug Set via attributes right now. Bug 271720. (XXX)
mElement->SetAttribute(NS_LITERAL_STRING("disabled"),
NS_LITERAL_STRING("1"));
mElement->RemoveAttribute(NS_LITERAL_STRING("enabled"));
nsCOMPtr<nsIXTFElementWrapper> xtfWrap(do_QueryInterface(mElement));
NS_ENSURE_STATE(xtfWrap);
xtfWrap->SetIntrinsicState(NS_EVENT_STATE_DISABLED);
// Dispatch event
nsXFormsUtils::DispatchEvent(mElement, eEvent_Disabled);
}
@ -528,9 +527,7 @@ nsXFormsControlStubBase::Create(nsIXTFElementWrapper *aWrapper)
ResetHelpAndHint(PR_TRUE);
// enabled is on pr. default
///
/// @bug This is only a hack until bug 271720 is landed (XXX)
mElement->SetAttribute(kStateAttributes[6], NS_LITERAL_STRING("1"));
aWrapper->SetIntrinsicState(NS_EVENT_STATE_ENABLED);
#ifdef DEBUG_smaug
sControlList->AppendElement(this);
@ -667,20 +664,13 @@ nsXFormsControlStubBase::GetContext(nsAString &aModelID,
void
nsXFormsControlStubBase::ResetProperties()
{
if (!mElement) {
nsCOMPtr<nsIXTFElementWrapper> xtfWrap(do_QueryInterface(mElement));
if (!xtfWrap) {
return;
}
///
/// @todo removes the attributes we use, until bug 271720 is landed (XXX)
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(kStateAttributes); ++i) {
mElement->RemoveAttribute(kStateAttributes[i]);
}
// enabled is on pr. default
///
/// @bug This is only a hack until bug 271720 is landed (XXX)
mElement->SetAttribute(kStateAttributes[6], NS_LITERAL_STRING("1"));
xtfWrap->SetIntrinsicState(NS_EVENT_STATE_ENABLED);
}
void

View File

@ -76,6 +76,7 @@
#include "nsAutoPtr.h"
#include "nsArray.h"
#include "nsIDOMDocumentXBL.h"
#include "nsIEventStateManager.h"
#define XFORMS_LAZY_INSTANCE_BINDING \
"chrome://xforms/content/xforms.xml#xforms-lazy-instance"
@ -624,18 +625,10 @@ nsXFormsModelElement::Recalculate()
void
nsXFormsModelElement::SetSingleState(nsIDOMElement *aElement,
PRBool aState,
nsXFormsEvent aOnEvent,
PRUint32 aAttributePos)
nsXFormsEvent aOnEvent)
{
nsXFormsEvent event = aState ? aOnEvent : (nsXFormsEvent) (aOnEvent + 1);
// Set pseudo class
///
/// @bug Set via attributes right now. Bug 271720. (XXX)
aElement->SetAttribute(kStateAttributes[aState ? aAttributePos : aAttributePos + 1],
NS_LITERAL_STRING("1"));
aElement->RemoveAttribute(kStateAttributes[aState ? aAttributePos + 1 : aAttributePos]);
// Dispatch event
nsXFormsUtils::DispatchEvent(aElement, event);
}
@ -653,25 +646,38 @@ nsXFormsModelElement::SetStatesInternal(nsIXFormsControl *aControl,
aControl->GetElement(getter_AddRefs(element));
NS_ENSURE_STATE(element);
nsCOMPtr<nsIXTFElementWrapper> xtfWrap(do_QueryInterface(element));
NS_ENSURE_STATE(xtfWrap);
const nsXFormsNodeState *ns = mMDG.GetNodeState(aNode);
NS_ENSURE_STATE(ns);
/// @todo the last argument (0, 2, 4, and 6) to SetSingleState is the
/// position of the attribute in kStateAttributes. It's hacky and only
/// temporary, until bug 271720 lands. (XXX)
// XXX nsXFormsNodeState could expose a bitmask using NS_EVENTs, to avoid
// most of this...
PRBool tmp = ns->IsValid();
PRUint32 state = tmp ? NS_EVENT_STATE_VALID : NS_EVENT_STATE_INVALID;
if (aAllStates || ns->ShouldDispatchValid()) {
SetSingleState(element, ns->IsValid(), eEvent_Valid, 0);
SetSingleState(element, tmp, eEvent_Valid);
}
tmp = ns->IsReadonly();
state |= tmp ? NS_EVENT_STATE_MOZ_READONLY : NS_EVENT_STATE_MOZ_READWRITE;
if (aAllStates || ns->ShouldDispatchReadonly()) {
SetSingleState(element, ns->IsReadonly(), eEvent_Readonly, 2);
SetSingleState(element, tmp, eEvent_Readonly);
}
tmp = ns->IsRequired();
state |= tmp ? NS_EVENT_STATE_REQUIRED : NS_EVENT_STATE_OPTIONAL;
if (aAllStates || ns->ShouldDispatchRequired()) {
SetSingleState(element, ns->IsRequired(), eEvent_Required, 4);
SetSingleState(element, tmp, eEvent_Required);
}
tmp = ns->IsRelevant();
state |= tmp ? NS_EVENT_STATE_ENABLED : NS_EVENT_STATE_DISABLED;
if (aAllStates || ns->ShouldDispatchRelevant()) {
SetSingleState(element, ns->IsRelevant(), eEvent_Enabled, 6);
SetSingleState(element, tmp, eEvent_Enabled);
}
nsresult rv = xtfWrap->SetIntrinsicState(state);
NS_ENSURE_SUCCESS(rv, rv);
if (ns->ShouldDispatchValueChanged()) {
nsXFormsUtils::DispatchEvent(element, eEvent_ValueChanged);
}

View File

@ -161,14 +161,10 @@ private:
* @param aElement The element to dispatch events to and set states on
* @param aState The state value
* @param aOnEvent The on event for the state.
* @param aAttributePos The position of the "on" attribute in kStateAttributes
*
* @note aAttributePos is only needed until bug 271720 is landed.
*/
NS_HIDDEN_(void) SetSingleState(nsIDOMElement *aElement,
PRBool aState,
nsXFormsEvent aOnEvent,
PRUint32 aAttributePos);
nsXFormsEvent aOnEvent);
/**
* Call the Bind() and Refresh() on controls which was deferred because

View File

@ -173,19 +173,6 @@ static const EventData sEventDefaultsEntries[] = {
static nsDataHashtable<nsStringHashKey,PRUint32> sXFormsEvents;
static nsDataHashtable<nsStringHashKey,PRUint32> sEventDefaults;
/**
* @todo The attribute names used on the elements to reflect the pseudo class
* state until bug 271720 is landed. (XXX)
*/
const nsString kStateAttributes[8] = { NS_LITERAL_STRING("valid"),
NS_LITERAL_STRING("invalid"),
NS_LITERAL_STRING("read-only"),
NS_LITERAL_STRING("read-write"),
NS_LITERAL_STRING("required"),
NS_LITERAL_STRING("optional"),
NS_LITERAL_STRING("enabled"),
NS_LITERAL_STRING("disabled") };
/* static */ nsresult
nsXFormsUtils::Init()
{

View File

@ -127,12 +127,6 @@ struct EventData
extern const EventData sXFormsEventsEntries[42];
/**
* @todo The attribute names used on the elements to reflect the pseudo class
* state until bug 271720 is landed. (XXX)
*/
extern const nsString kStateAttributes[8];
/**
* This class has static helper methods that don't fit into a specific place
* in the class hierarchy.