Bug 717066 - Make nsGenericHTMLElement::GetLayoutHistoryAndKey return void. r=ms2ger
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -1546,92 +1546,85 @@ nsGenericHTMLElement::GetFormControlFram
nsGenericHTMLElement::GetPrimaryPresState(nsGenericHTMLElement* aContent,
nsPresState** aPresState)
{
NS_ENSURE_ARG_POINTER(aPresState);
*aPresState = nsnull;
nsresult result = NS_OK;
- nsCOMPtr<nsILayoutHistoryState> history;
nsCAutoString key;
- GetLayoutHistoryAndKey(aContent, false, getter_AddRefs(history), key);
+ nsCOMPtr<nsILayoutHistoryState> history = GetLayoutHistoryAndKey(aContent, false, key);
if (history) {
// Get the pres state for this key, if it doesn't exist, create one
result = history->GetState(key, aPresState);
if (!*aPresState) {
*aPresState = new nsPresState();
result = history->AddState(key, *aPresState);
}
}
return result;
}
-nsresult
+already_AddRefed<nsILayoutHistoryState>
nsGenericHTMLElement::GetLayoutHistoryAndKey(nsGenericHTMLElement* aContent,
bool aRead,
- nsILayoutHistoryState** aHistory,
nsACString& aKey)
{
//
// Get the pres shell
//
nsCOMPtr<nsIDocument> doc = aContent->GetDocument();
if (!doc) {
- return NS_OK;
+ return nsnull;
}
//
// Get the history (don't bother with the key if the history is not there)
//
- *aHistory = doc->GetLayoutHistoryState().get();
- if (!*aHistory) {
- return NS_OK;
+ nsCOMPtr<nsILayoutHistoryState> history = doc->GetLayoutHistoryState();
+ if (!history) {
+ return nsnull;
}
- if (aRead && !(*aHistory)->HasStates()) {
- NS_RELEASE(*aHistory);
- return NS_OK;
+ if (aRead && !history->HasStates()) {
+ return nsnull;
}
//
// Get the state key
//
nsresult rv = nsContentUtils::GenerateStateKey(aContent, doc,
nsIStatefulFrame::eNoID,
aKey);
if (NS_FAILED(rv)) {
- NS_RELEASE(*aHistory);
- return rv;
+ return nsnull;
}
// If the state key is blank, this is anonymous content or for
// whatever reason we are not supposed to save/restore state.
if (aKey.IsEmpty()) {
- NS_RELEASE(*aHistory);
- return NS_OK;
+ return nsnull;
}
// Add something unique to content so layout doesn't muck us up
aKey += "-C";
- return rv;
+ return history.forget();
}
bool
nsGenericHTMLElement::RestoreFormControlState(nsGenericHTMLElement* aContent,
nsIFormControl* aControl)
{
- nsCOMPtr<nsILayoutHistoryState> history;
nsCAutoString key;
- GetLayoutHistoryAndKey(aContent, true,
- getter_AddRefs(history), key);
+ nsCOMPtr<nsILayoutHistoryState> history = GetLayoutHistoryAndKey(aContent, true, key);
if (!history) {
return false;
}
nsPresState *state;
// Get the pres state for this key
nsresult rv = history->GetState(key, &state);
if (NS_SUCCEEDED(rv) && state) {
--- a/content/html/content/src/nsGenericHTMLElement.h
+++ b/content/html/content/src/nsGenericHTMLElement.h
@@ -466,20 +466,20 @@ 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,
- bool aRead,
- nsILayoutHistoryState** aState,
- nsACString& aKey);
+ static already_AddRefed<nsILayoutHistoryState>
+ GetLayoutHistoryAndKey(nsGenericHTMLElement* aContent,
+ bool aRead,
+ nsACString& aKey);
/**
* Restore the state for a form control. Ends up calling
* nsIFormControl::RestoreState().
*
* @param aContent an nsGenericHTMLElement* pointing to the form control
* @param aControl an nsIFormControl* pointing to the form control
* @return false if RestoreState() was not called, the return
* value of RestoreState() otherwise.
@@ -864,17 +864,17 @@ public:
virtual void ClearForm(bool aRemoveFromForm);
nsresult GetForm(nsIDOMHTMLFormElement** aForm);
NS_IMETHOD SaveState()
{
return NS_OK;
}
-
+
virtual bool RestoreState(nsPresState* aState)
{
return false;
}
virtual bool AllowDrop()
{
return true;
}