bug 218297 : disabled property of input elements is not stored in history

r=jkeiser sr=jst
This commit is contained in:
hpradhan%hotpop.com 2003-11-10 05:52:29 +00:00
Родитель d3554040e1
Коммит 03e43cda2b
7 изменённых файлов: 108 добавлений и 16 удалений

Просмотреть файл

@ -76,6 +76,7 @@
#include "nsGUIEvent.h"
#include "nsIPresState.h"
#include "nsLayoutErrors.h"
#include "nsIDOMEvent.h"
#include "nsIDOMNSEvent.h"
#include "nsIDOMNodeList.h"
@ -115,7 +116,7 @@ static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID);
//
// Accessors for mBitField
//
// #define BF_SKIP_FOCUS_EVENT 0 no longer used
#define BF_DISABLED_CHANGED 0
#define BF_HANDLING_CLICK 1
#define BF_VALUE_CHANGED 2
#define BF_CHECKED_CHANGED 3
@ -592,7 +593,7 @@ NS_IMPL_STRING_ATTR(nsHTMLInputElement, AccessKey, accesskey)
NS_IMPL_STRING_ATTR(nsHTMLInputElement, Align, align)
NS_IMPL_STRING_ATTR(nsHTMLInputElement, Alt, alt)
//NS_IMPL_BOOL_ATTR(nsHTMLInputElement, Checked, checked)
NS_IMPL_BOOL_ATTR(nsHTMLInputElement, Disabled, disabled)
//NS_IMPL_BOOL_ATTR(nsHTMLInputElement, Disabled, disabled)
NS_IMPL_INT_ATTR(nsHTMLInputElement, MaxLength, maxlength)
NS_IMPL_STRING_ATTR(nsHTMLInputElement, Name, name)
NS_IMPL_BOOL_ATTR(nsHTMLInputElement, ReadOnly, readonly)
@ -601,6 +602,29 @@ NS_IMPL_INT_ATTR(nsHTMLInputElement, TabIndex, tabindex)
NS_IMPL_STRING_ATTR(nsHTMLInputElement, UseMap, usemap)
//NS_IMPL_STRING_ATTR(nsHTMLInputElement, Value, value)
NS_IMETHODIMP
nsHTMLInputElement::GetDisabled(PRBool* aDisabled)
{
nsHTMLValue val;
nsresult rv = GetHTMLAttribute(nsHTMLAtoms::disabled, val);
*aDisabled = (NS_CONTENT_ATTR_NOT_THERE != rv);
return NS_OK;
}
NS_IMETHODIMP
nsHTMLInputElement::SetDisabled(PRBool aDisabled)
{
SET_BOOLBIT(mBitField, BF_DISABLED_CHANGED, PR_TRUE);
if (aDisabled) {
nsHTMLValue empty(eHTMLUnit_Empty);
return SetHTMLAttribute(nsHTMLAtoms::disabled, empty, PR_TRUE);
}
UnsetAttr(kNameSpaceID_None, nsHTMLAtoms::disabled, PR_TRUE);
return NS_OK;
}
NS_IMETHODIMP
nsHTMLInputElement::GetSize(PRUint32* aValue)
{
@ -2538,6 +2562,22 @@ nsHTMLInputElement::SaveState()
break;
}
}
if (GET_BOOLBIT(mBitField, BF_DISABLED_CHANGED)) {
rv |= GetPrimaryPresState(this, getter_AddRefs(state));
if (state) {
PRBool disabled;
GetDisabled(&disabled);
if (disabled) {
rv |= state->SetStateProperty(NS_LITERAL_STRING("disabled"),
NS_LITERAL_STRING("t"));
} else {
rv |= state->SetStateProperty(NS_LITERAL_STRING("disabled"),
NS_LITERAL_STRING("f"));
}
NS_ASSERTION(NS_SUCCEEDED(rv), "disabled save failed!");
}
}
return rv;
}
@ -2595,10 +2635,9 @@ nsHTMLInputElement::RestoreState(nsIPresState* aState)
{
nsAutoString checked;
rv = aState->GetStateProperty(NS_LITERAL_STRING("checked"), checked);
// We assume that we are the only ones who saved the state. Thus we
// know the exact value that would have been saved.
SetChecked(checked.Equals(NS_LITERAL_STRING("t")));
if (rv == NS_STATE_PROPERTY_EXISTS) {
SetChecked(checked.Equals(NS_LITERAL_STRING("t")));
}
break;
}
@ -2609,12 +2648,25 @@ nsHTMLInputElement::RestoreState(nsIPresState* aState)
nsAutoString value;
rv = aState->GetStateProperty(NS_LITERAL_STRING("v"), value);
NS_ASSERTION(NS_SUCCEEDED(rv), "value restore failed!");
SetValueInternal(value, nsnull);
if (rv == NS_STATE_PROPERTY_EXISTS) {
SetValueInternal(value, nsnull);
}
break;
}
}
nsAutoString disabled;
nsresult rv2 = aState->GetStateProperty(NS_LITERAL_STRING("disabled"), disabled);
NS_ASSERTION(NS_SUCCEEDED(rv2), "disabled restore failed!");
if (rv2 == NS_STATE_PROPERTY_EXISTS) {
SetDisabled(disabled.Equals(NS_LITERAL_STRING("t")));
}
return rv;
if (NS_FAILED(rv|rv2)) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}

Просмотреть файл

@ -17,6 +17,14 @@ public:
NS_IMETHOD SetStatePropertyAsSupports(const nsAString& aName,
nsISupports* aValue) = 0;
/**
* Get the current value of a property.
*
* @param aName the name of the property.
* @param aResult the value (may legitimately be the empty string) [OUT]
* @throws NS_STATE_PROPERTY_NOT_THERE if the property is not set
* @throws NS_STATE_PROPERTY_EXISTS if the attribute exists (==NS_OK)
*/
NS_IMETHOD GetStateProperty(const nsAString& aName,
nsAString& aResult) = 0;
NS_IMETHOD SetStateProperty(const nsAString& aProperty,

Просмотреть файл

@ -60,4 +60,15 @@
replaced by alt text or something like that **/
#define NS_ERROR_FRAME_REPLACED \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_LAYOUT, 4)
/** Error codes for nsIPresState::GetProperty() */
/** Returned if the property exists */
#define NS_STATE_PROPERTY_EXISTS NS_OK
/** Returned if the property does not exist */
#define NS_STATE_PROPERTY_NOT_THERE \
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_LAYOUT, 5)
#endif // nsLayoutErrors_h___

Просмотреть файл

@ -43,9 +43,8 @@
#include "nsIComponentManager.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsLayoutErrors.h"
// Static IIDs/CIDs. Try to minimize these.
// None
class nsPresState: public nsIPresState
@ -100,7 +99,8 @@ NS_IMETHODIMP
nsPresState::GetStateProperty(const nsAString& aName,
nsAString& aResult)
{
aResult.SetLength(0);
nsresult rv = NS_STATE_PROPERTY_NOT_THERE;
aResult.Truncate();
// Retrieve from hashtable.
if (mPropertyTable) {
@ -116,10 +116,11 @@ nsPresState::GetStateProperty(const nsAString& aName,
supportsStr->GetData(data);
CopyUTF8toUTF16(data, aResult);
rv = NS_STATE_PROPERTY_EXISTS;
}
}
return NS_OK;
return rv;
}
NS_IMETHODIMP

Просмотреть файл

@ -17,6 +17,14 @@ public:
NS_IMETHOD SetStatePropertyAsSupports(const nsAString& aName,
nsISupports* aValue) = 0;
/**
* Get the current value of a property.
*
* @param aName the name of the property.
* @param aResult the value (may legitimately be the empty string) [OUT]
* @throws NS_STATE_PROPERTY_NOT_THERE if the property is not set
* @throws NS_STATE_PROPERTY_EXISTS if the attribute exists (==NS_OK)
*/
NS_IMETHOD GetStateProperty(const nsAString& aName,
nsAString& aResult) = 0;
NS_IMETHOD SetStateProperty(const nsAString& aProperty,

Просмотреть файл

@ -60,4 +60,15 @@
replaced by alt text or something like that **/
#define NS_ERROR_FRAME_REPLACED \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_LAYOUT, 4)
/** Error codes for nsIPresState::GetProperty() */
/** Returned if the property exists */
#define NS_STATE_PROPERTY_EXISTS NS_OK
/** Returned if the property does not exist */
#define NS_STATE_PROPERTY_NOT_THERE \
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_LAYOUT, 5)
#endif // nsLayoutErrors_h___

Просмотреть файл

@ -43,9 +43,8 @@
#include "nsIComponentManager.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsLayoutErrors.h"
// Static IIDs/CIDs. Try to minimize these.
// None
class nsPresState: public nsIPresState
@ -100,7 +99,8 @@ NS_IMETHODIMP
nsPresState::GetStateProperty(const nsAString& aName,
nsAString& aResult)
{
aResult.SetLength(0);
nsresult rv = NS_STATE_PROPERTY_NOT_THERE;
aResult.Truncate();
// Retrieve from hashtable.
if (mPropertyTable) {
@ -116,10 +116,11 @@ nsPresState::GetStateProperty(const nsAString& aName,
supportsStr->GetData(data);
CopyUTF8toUTF16(data, aResult);
rv = NS_STATE_PROPERTY_EXISTS;
}
}
return NS_OK;
return rv;
}
NS_IMETHODIMP