Don't generate state keys at all, if there's nothing to get. Bug 388387, r+sr=sicking.

git-svn-id: svn://10.0.0.236/trunk@230408 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bzbarsky%mit.edu
2007-07-21 03:00:03 +00:00
parent a9121164a8
commit de3dca4e60
4 changed files with 26 additions and 4 deletions

View File

@@ -1733,7 +1733,7 @@ nsGenericHTMLElement::GetPrimaryPresState(nsGenericHTMLElement* aContent,
nsCOMPtr<nsILayoutHistoryState> history;
nsCAutoString key;
GetLayoutHistoryAndKey(aContent, getter_AddRefs(history), key);
GetLayoutHistoryAndKey(aContent, PR_FALSE, getter_AddRefs(history), key);
if (history) {
// Get the pres state for this key, if it doesn't exist, create one
@@ -1752,6 +1752,7 @@ nsGenericHTMLElement::GetPrimaryPresState(nsGenericHTMLElement* aContent,
nsresult
nsGenericHTMLElement::GetLayoutHistoryAndKey(nsGenericHTMLElement* aContent,
PRBool aRead,
nsILayoutHistoryState** aHistory,
nsACString& aKey)
{
@@ -1771,6 +1772,11 @@ nsGenericHTMLElement::GetLayoutHistoryAndKey(nsGenericHTMLElement* aContent,
return NS_OK;
}
if (aRead && !(*aHistory)->HasStates()) {
NS_RELEASE(*aHistory);
return NS_OK;
}
//
// Get the state key
//
@@ -1801,7 +1807,8 @@ nsGenericHTMLElement::RestoreFormControlState(nsGenericHTMLElement* aContent,
{
nsCOMPtr<nsILayoutHistoryState> history;
nsCAutoString key;
nsresult rv = GetLayoutHistoryAndKey(aContent, getter_AddRefs(history), key);
nsresult rv = GetLayoutHistoryAndKey(aContent, PR_TRUE,
getter_AddRefs(history), key);
if (!history) {
return PR_FALSE;
}

View File

@@ -527,10 +527,13 @@ public:
* piece of content.
*
* @param aContent the content to generate the key for
* @param aRead if true, won't return a layout history state (and won't
* generate a key) if the layout history state is empty.
* @param aState the history state object (out param)
* @param aKey the key (out param)
*/
static nsresult GetLayoutHistoryAndKey(nsGenericHTMLElement* aContent,
PRBool aRead,
nsILayoutHistoryState** aState,
nsACString& aKey);
/**

View File

@@ -50,8 +50,8 @@
class nsPresState;
#define NS_ILAYOUTHISTORYSTATE_IID \
{0xe6abfb7c, 0x6624, 0x4b4d, \
{0x9d, 0xfe, 0xea, 0x62, 0xae, 0xfe, 0x03, 0x31}}
{ 0x99003f0f, 0x7ade, 0x44a1, \
{ 0x81, 0x74, 0xe3, 0x6a, 0xa5, 0xbb, 0x6b, 0x10 } }
class nsILayoutHistoryState : public nsISupports {
public:
@@ -74,6 +74,11 @@ class nsILayoutHistoryState : public nsISupports {
* Remove the state object for |aKey|.
*/
NS_IMETHOD RemoveState(const nsCString& aKey) = 0;
/**
* Check whether this history has any states in it
*/
NS_IMETHOD_(PRBool) HasStates() const = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsILayoutHistoryState,

View File

@@ -58,6 +58,7 @@ public:
NS_IMETHOD AddState(const nsCString& aKey, nsPresState* aState);
NS_IMETHOD GetState(const nsCString& aKey, nsPresState** aState);
NS_IMETHOD RemoveState(const nsCString& aKey);
NS_IMETHOD_(PRBool) HasStates() const;
private:
@@ -116,3 +117,9 @@ nsLayoutHistoryState::RemoveState(const nsCString& aKey)
mStates.Remove(aKey);
return NS_OK;
}
NS_IMETHODIMP_(PRBool)
nsLayoutHistoryState::HasStates() const
{
return mStates.Count() != 0;
}