From 317b99e5a53595b4687d87518a08fd8524b0012b Mon Sep 17 00:00:00 2001 From: "jkeiser%netscape.com" Date: Fri, 29 Mar 2002 07:35:09 +0000 Subject: [PATCH] Backing out 108308 due to pageload spike git-svn-id: svn://10.0.0.236/trunk@117722 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/public/nsIContent.h | 28 --- .../content/base/src/nsGenericDOMDataNode.cpp | 5 - .../content/base/src/nsGenericDOMDataNode.h | 1 - mozilla/content/base/src/nsGenericElement.cpp | 6 - mozilla/content/base/src/nsGenericElement.h | 1 - .../content/html/content/public/MANIFEST_IDL | 1 - .../content/html/content/public/Makefile.in | 1 - .../content/html/content/public/makefile.win | 1 - .../html/content/public/nsIFormControl.h | 7 +- .../html/content/public/nsISelectElement.idl | 16 +- .../content/public/nsITextAreaElement.idl | 54 ------ .../html/content/src/nsAttributeContent.cpp | 4 - .../html/content/src/nsGenericHTMLElement.cpp | 116 +++--------- .../html/content/src/nsGenericHTMLElement.h | 60 +++---- .../html/content/src/nsHTMLInputElement.cpp | 167 +++++++----------- .../html/content/src/nsHTMLSelectElement.cpp | 66 ++++--- .../content/src/nsHTMLTextAreaElement.cpp | 57 +++--- .../html/document/src/nsHTMLContentSink.cpp | 49 ++--- mozilla/content/macbuild/contentIDL.xml | 30 ---- .../content/xul/content/src/nsXULElement.cpp | 5 - .../content/xul/content/src/nsXULElement.h | 1 - mozilla/layout/base/nsFrameManager.cpp | 17 +- mozilla/layout/base/public/nsIFrameManager.h | 2 +- .../layout/forms/nsComboboxControlFrame.cpp | 7 +- mozilla/layout/forms/nsComboboxControlFrame.h | 2 +- mozilla/layout/forms/nsFileControlFrame.cpp | 66 +++++-- mozilla/layout/forms/nsFileControlFrame.h | 9 +- mozilla/layout/forms/nsFormControlHelper.cpp | 34 ++++ mozilla/layout/forms/nsFormControlHelper.h | 6 + .../layout/forms/nsGfxButtonControlFrame.cpp | 47 +++++ .../layout/forms/nsGfxButtonControlFrame.h | 8 +- .../forms/nsGfxCheckboxControlFrame.cpp | 20 ++- .../layout/forms/nsGfxCheckboxControlFrame.h | 6 + .../layout/forms/nsGfxRadioControlFrame.cpp | 23 +++ mozilla/layout/forms/nsGfxRadioControlFrame.h | 6 + mozilla/layout/forms/nsISelectControlFrame.h | 5 +- mozilla/layout/forms/nsListControlFrame.cpp | 39 +++- mozilla/layout/forms/nsListControlFrame.h | 8 +- .../layout/html/base/src/nsFrameManager.cpp | 17 +- .../html/forms/public/nsISelectControlFrame.h | 5 +- .../html/forms/src/nsComboboxControlFrame.cpp | 7 +- .../html/forms/src/nsComboboxControlFrame.h | 2 +- .../html/forms/src/nsFileControlFrame.cpp | 66 +++++-- .../html/forms/src/nsFileControlFrame.h | 9 +- .../html/forms/src/nsFormControlHelper.cpp | 34 ++++ .../html/forms/src/nsFormControlHelper.h | 6 + .../forms/src/nsGfxButtonControlFrame.cpp | 47 +++++ .../html/forms/src/nsGfxButtonControlFrame.h | 8 +- .../forms/src/nsGfxCheckboxControlFrame.cpp | 20 ++- .../forms/src/nsGfxCheckboxControlFrame.h | 6 + .../html/forms/src/nsGfxRadioControlFrame.cpp | 23 +++ .../html/forms/src/nsGfxRadioControlFrame.h | 6 + .../html/forms/src/nsGfxTextControlFrame2.cpp | 19 ++ .../html/forms/src/nsGfxTextControlFrame2.h | 6 + .../html/forms/src/nsListControlFrame.cpp | 39 +++- .../html/forms/src/nsListControlFrame.h | 8 +- 56 files changed, 752 insertions(+), 557 deletions(-) delete mode 100644 mozilla/content/html/content/public/nsITextAreaElement.idl diff --git a/mozilla/content/base/public/nsIContent.h b/mozilla/content/base/public/nsIContent.h index 8a104f0bc80..e5c4237995f 100644 --- a/mozilla/content/base/public/nsIContent.h +++ b/mozilla/content/base/public/nsIContent.h @@ -309,34 +309,6 @@ public: NS_IMETHOD GetListenerManager(nsIEventListenerManager** aResult) = 0; - /** - * This method is called when the parser finishes creating the element. This - * particularly means that it has done everything you would expect it to have - * done after it encounters the > at the end of the tag (for HTML or XML). - * This includes setting the attributes, setting the document / form, and - * placing the element into the tree at its proper place. - * - * For container elements, this is called *before* any of the children are - * created or added into the tree. - * - * NOTE: this is currently only called for input and button, in the HTML - * content sink. If you want to call it on your element, modify the content - * sink of your choice to do so. This is an efficiency measure. - * - * If you also need to determine whether the parser is the one creating your - * element (through createElement() or cloneNode() generally) * aFromParser to the NS_NewXXX() constructor for your element and have the - * parser pass true. See nsHTMLInputElement.cpp and - * nsHTMLContentSink::MakeContentObject(). - * - * DO NOT USE THIS METHOD to get around the fact that it's hard to deal with - * attributes dynamically. If you make attributes affect your element from - * this method, it will only happen on initialization and JavaScript will not - * be able to create elements (which requires them to first create the - * element and then call setAttribute() directly, at which point - * DoneCreatingElement() has already been called and is out of the picture). - */ - NS_IMETHOD DoneCreatingElement() = 0; - #ifdef DEBUG /** * Get the size of the content object. The size value should include diff --git a/mozilla/content/base/src/nsGenericDOMDataNode.cpp b/mozilla/content/base/src/nsGenericDOMDataNode.cpp index 47f9b826040..b9c7b2dbc78 100644 --- a/mozilla/content/base/src/nsGenericDOMDataNode.cpp +++ b/mozilla/content/base/src/nsGenericDOMDataNode.cpp @@ -641,11 +641,6 @@ nsGenericDOMDataNode::GetListenerManager(nsIEventListenerManager** aResult) return NS_OK; } -NS_IMETHODIMP -nsGenericDOMDataNode::DoneCreatingElement() -{ - return NS_OK; -} //---------------------------------------------------------------------- // Implementation of nsIContent diff --git a/mozilla/content/base/src/nsGenericDOMDataNode.h b/mozilla/content/base/src/nsGenericDOMDataNode.h index 409ff3d4429..1823798ff2f 100644 --- a/mozilla/content/base/src/nsGenericDOMDataNode.h +++ b/mozilla/content/base/src/nsGenericDOMDataNode.h @@ -210,7 +210,6 @@ public: NS_IMETHOD_(PRBool) IsContentOfType(PRUint32 aFlags); NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult); - NS_IMETHOD DoneCreatingElement(); #ifdef DEBUG NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; diff --git a/mozilla/content/base/src/nsGenericElement.cpp b/mozilla/content/base/src/nsGenericElement.cpp index 89d652f6549..14f9e2fb871 100644 --- a/mozilla/content/base/src/nsGenericElement.cpp +++ b/mozilla/content/base/src/nsGenericElement.cpp @@ -2040,12 +2040,6 @@ nsGenericElement::GetListenerManager(nsIEventListenerManager** aResult) return rv; } -NS_IMETHODIMP -nsGenericElement::DoneCreatingElement() -{ - return NS_OK; -} - //---------------------------------------------------------------------- // Generic DOMNode implementations diff --git a/mozilla/content/base/src/nsGenericElement.h b/mozilla/content/base/src/nsGenericElement.h index e5b9a3b83ab..bd65b4ef6e6 100644 --- a/mozilla/content/base/src/nsGenericElement.h +++ b/mozilla/content/base/src/nsGenericElement.h @@ -251,7 +251,6 @@ public: NS_IMETHOD SetBindingParent(nsIContent* aParent); NS_IMETHOD_(PRBool) IsContentOfType(PRUint32 aFlags); NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult); - NS_IMETHOD DoneCreatingElement(); // nsIStyledContent interface methods diff --git a/mozilla/content/html/content/public/MANIFEST_IDL b/mozilla/content/html/content/public/MANIFEST_IDL index 45f83a30314..8c2f1675be1 100644 --- a/mozilla/content/html/content/public/MANIFEST_IDL +++ b/mozilla/content/html/content/public/MANIFEST_IDL @@ -3,4 +3,3 @@ # nsISelectElement.idl -nsITextAreaElement.idl diff --git a/mozilla/content/html/content/public/Makefile.in b/mozilla/content/html/content/public/Makefile.in index 6d33674c0d1..095b3219dff 100644 --- a/mozilla/content/html/content/public/Makefile.in +++ b/mozilla/content/html/content/public/Makefile.in @@ -31,7 +31,6 @@ XPIDL_MODULE = content_html XPIDLSRCS = \ nsISelectElement.idl \ - nsITextAreaElement.idl \ $(NULL) EXPORTS = \ diff --git a/mozilla/content/html/content/public/makefile.win b/mozilla/content/html/content/public/makefile.win index 289d7de8209..f8b3dc35fe8 100644 --- a/mozilla/content/html/content/public/makefile.win +++ b/mozilla/content/html/content/public/makefile.win @@ -23,7 +23,6 @@ DEPTH=..\..\..\.. XPIDLSRCS = \ .\nsISelectElement.idl \ - .\nsITextAreaElement.idl \ $(NULL) EXPORTS= \ diff --git a/mozilla/content/html/content/public/nsIFormControl.h b/mozilla/content/html/content/public/nsIFormControl.h index c201fa37171..c12270eaa6d 100644 --- a/mozilla/content/html/content/public/nsIFormControl.h +++ b/mozilla/content/html/content/public/nsIFormControl.h @@ -131,13 +131,14 @@ public: /** * Save to presentation state */ - NS_IMETHOD SaveState() = 0; + NS_IMETHOD SaveState(nsIPresContext* aPresContext, + nsIPresState** aState) = 0; /** * Restore from presentation state - * @param aState the pres state to use to restore the control */ - NS_IMETHOD RestoreState(nsIPresState* aState) = 0; + NS_IMETHOD RestoreState(nsIPresContext* aPresContext, + nsIPresState* aState) = 0; }; #endif /* nsIFormControl_h___ */ diff --git a/mozilla/content/html/content/public/nsISelectElement.idl b/mozilla/content/html/content/public/nsISelectElement.idl index ffce7df44b3..b8a8dcd97e1 100644 --- a/mozilla/content/html/content/public/nsISelectElement.idl +++ b/mozilla/content/html/content/public/nsISelectElement.idl @@ -83,18 +83,16 @@ interface nsISelectElement : nsISupports [noscript] void removeOption(in nsIContent aContent); /** - * Called when the parser is done adding child content + * Indicates that we're done adding child content * to the select during document loading. */ - void doneAddingChildren(); + void doneAddingContent(in boolean aIsDone); /** - * Returns whether the parser is done adding child content + * Returns whether we're done adding child content * to the select during document loading. - * - * @return whether the parser is done adding children */ - boolean isDoneAddingChildren(); + boolean isDoneAddingContent(); /** * Returns whether we're the option is selected @@ -130,6 +128,8 @@ interface nsISelectElement : nsISupports /** * Called to save/restore to/from pres. state */ - [noscript] void saveState(); - [noscript] void restoreState(in nsIPresState aState); + [noscript] void saveState(in nsIPresContext aPresContext, + out nsIPresState aState); + [noscript] void restoreState(in nsIPresContext aPresContext, + in nsIPresState aState); }; diff --git a/mozilla/content/html/content/public/nsITextAreaElement.idl b/mozilla/content/html/content/public/nsITextAreaElement.idl deleted file mode 100644 index 29a4bd89936..00000000000 --- a/mozilla/content/html/content/public/nsITextAreaElement.idl +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsISupports.idl" - -/** - * This interface is used so that the parser can notify the textarea when - * it has finished loading content. - */ - -[scriptable, uuid(36878df2-1dd2-11b2-99a0-ea9fab347485)] -interface nsITextAreaElement : nsISupports -{ - /** - * Called when the parser is done adding child content - * to the select during document loading. - */ - void doneAddingChildren(); -}; diff --git a/mozilla/content/html/content/src/nsAttributeContent.cpp b/mozilla/content/html/content/src/nsAttributeContent.cpp index 109c0ee8cf8..316ff8a39f4 100644 --- a/mozilla/content/html/content/src/nsAttributeContent.cpp +++ b/mozilla/content/html/content/src/nsAttributeContent.cpp @@ -139,10 +139,6 @@ public: return NS_ERROR_NOT_IMPLEMENTED; } - NS_IMETHOD DoneCreatingElement() { - return NS_OK; - } - NS_IMETHOD SetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute, const nsAString& aValue, PRBool aNotify) { return NS_OK; } NS_IMETHOD SetAttr(nsINodeInfo *aNodeInfo, const nsAString& aValue, diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp index 05f6ed48178..eef97415d80 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp @@ -2951,98 +2951,44 @@ nsGenericHTMLElement::GetPrimaryPresState(nsIHTMLContent* aContent, nsresult result = NS_OK; - nsCOMPtr history; - nsCAutoString key; - GetLayoutHistoryAndKey(aContent, getter_AddRefs(history), key); - - if (history) { - // Get the pres state for this key, if it doesn't exist, create one - result = history->GetState(key, aPresState); - if (!*aPresState) { - result = nsComponentManager::CreateInstance(kPresStateCID, nsnull, - NS_GET_IID(nsIPresState), - (void**)aPresState); - if (NS_SUCCEEDED(result)) { - result = history->AddState(key, *aPresState); - } - } - } - - return result; -} - - -nsresult -nsGenericHTMLElement::GetLayoutHistoryAndKey(nsIHTMLContent* aContent, - nsILayoutHistoryState** aHistory, - nsACString& aKey) -{ - // - // Get the pres shell - // + // Generate the state key nsCOMPtr doc; - nsresult rv = aContent->GetDocument(*getter_AddRefs(doc)); + result = aContent->GetDocument(*getter_AddRefs(doc)); if (!doc) { - return rv; + return result; } nsCOMPtr presShell; doc->GetShellAt(0, getter_AddRefs(presShell)); NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); - // - // Get the history (don't bother with the key if the history is not there) - // - rv = presShell->GetHistoryState(aHistory); - NS_ENSURE_SUCCESS(rv, rv); - if (!*aHistory) { - return NS_OK; - } - - // - // Get the state key - // nsCOMPtr frameManager; presShell->GetFrameManager(getter_AddRefs(frameManager)); NS_ENSURE_TRUE(frameManager, NS_ERROR_FAILURE); - rv = frameManager->GenerateStateKey(aContent, nsIStatefulFrame::eNoID, aKey); - NS_ENSURE_SUCCESS(rv, rv); + nsCAutoString stateKey; + result = frameManager->GenerateStateKey(aContent, nsIStatefulFrame::eNoID, stateKey); + NS_ENSURE_TRUE((NS_SUCCEEDED(result) && !stateKey.IsEmpty()), result); - // 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; - } - - // Add something unique to content so layout doesn't muck us up - aKey += "-C"; - - return rv; -} - -PRBool -nsGenericHTMLElement::RestoreFormControlState(nsIHTMLContent* aContent, - nsIFormControl* aControl) -{ + // Get the pres state for this key, if it doesn't exist, create one + // + // Return early if we can't get history - we don't want to create a + // new history state that is free-floating, not in history. nsCOMPtr history; - nsCAutoString key; - nsresult rv = GetLayoutHistoryAndKey(aContent, getter_AddRefs(history), key); - if (!history) { - return PR_FALSE; + result = presShell->GetHistoryState(getter_AddRefs(history)); + NS_ENSURE_TRUE(NS_SUCCEEDED(result) && history, result); + + history->GetState(stateKey, aPresState); + if (!*aPresState) { + result = nsComponentManager::CreateInstance(kPresStateCID, nsnull, + NS_GET_IID(nsIPresState), + (void**)aPresState); + if (NS_SUCCEEDED(result)) { + result = history->AddState(stateKey, *aPresState); + } } - nsCOMPtr state; - // Get the pres state for this key - rv = history->GetState(key, getter_AddRefs(state)); - if (state) { - rv = aControl->RestoreState(state); - history->RemoveState(key); - return NS_SUCCEEDED(rv); - } - - return PR_FALSE; + return result; } // XXX This creates a dependency between content and frames @@ -4254,11 +4200,6 @@ nsGenericHTMLContainerFormElement::SetDocument(nsIDocument* aDocument, { nsresult rv = NS_OK; - // Save state before doing anything if the document is being removed - if (!aDocument) { - SaveState(); - } - if (aDocument && mParent && !mForm) { rv = FindAndSetForm(this); } else if (!aDocument && mForm) { @@ -4285,7 +4226,6 @@ nsGenericHTMLContainerFormElement::SetDocument(nsIDocument* aDocument, return rv; } - nsresult nsGenericHTMLElement::SetFormControlAttribute(nsIForm* aForm, PRInt32 aNameSpaceID, @@ -4504,11 +4444,6 @@ nsGenericHTMLLeafFormElement::SetDocument(nsIDocument* aDocument, { nsresult rv = NS_OK; - // Save state before doing anything if the document is being removed - if (!aDocument) { - SaveState(); - } - if (aDocument && mParent && !mForm) { rv = FindAndSetForm(this); } else if (!aDocument && mForm) { @@ -4535,13 +4470,6 @@ nsGenericHTMLLeafFormElement::SetDocument(nsIDocument* aDocument, return rv; } -NS_IMETHODIMP -nsGenericHTMLLeafFormElement::DoneCreatingElement() -{ - RestoreFormControlState(this, this); - return NS_OK; -} - NS_IMETHODIMP nsGenericHTMLLeafFormElement::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.h b/mozilla/content/html/content/src/nsGenericHTMLElement.h index f9bd9042635..ba70ef0e87f 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.h +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.h @@ -53,6 +53,7 @@ class nsIDOMAttr; class nsIDOMEventListener; class nsIDOMNodeList; +class nsIEventListenerManager; class nsIFrame; class nsHTMLAttributes; class nsIHTMLMappedAttributes; @@ -67,7 +68,6 @@ class nsIFormControlFrame; class nsIForm; class nsIPresState; class nsIScrollableView; -class nsILayoutHistoryState; struct nsRect; @@ -357,38 +357,8 @@ public: static nsIFormControlFrame* GetFormControlFrameFor(nsIContent* aContent, nsIDocument* aDocument, PRBool aFlushContent); - /** - * Get the presentation state for a piece of content, or create it if it does - * not exist. Generally used by SaveState(). - * - * @param aContent the content to get presentation state for. - * @param aPresState the presentation state (out param) - */ static nsresult GetPrimaryPresState(nsIHTMLContent* aContent, nsIPresState** aPresState); - /** - * Get the layout history object *and* generate the key for a particular - * piece of content. - * - * @param aContent the content to generate the key for - * @param aState the history state object (out param) - * @param aKey the key (out param) - */ - static nsresult GetLayoutHistoryAndKey(nsIHTMLContent* aContent, - nsILayoutHistoryState** aState, - nsACString& aKey); - /** - * Restore the state for a form control. Ends up calling - * nsIFormControl::RestoreState(). - * - * @param aContent an nsIHTMLContent* pointing to the form control - * @param aControl an nsIFormControl* pointing to the form control - * @return whether or not the RestoreState() was called and exited - * successfully. - */ - static PRBool RestoreFormControlState(nsIHTMLContent* aContent, - nsIFormControl* aControl); - static nsresult GetPresContext(nsIHTMLContent* aContent, nsIPresContext** aPresContext); @@ -619,8 +589,14 @@ public: NS_IMETHOD GetForm(nsIDOMHTMLFormElement** aForm); NS_IMETHOD SetForm(nsIDOMHTMLFormElement* aForm, PRBool aRemoveFromForm = PR_TRUE); - NS_IMETHOD SaveState() { return NS_OK; } - NS_IMETHOD RestoreState(nsIPresState* aState) { return NS_OK; } + NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState) + { + return NS_OK; + } + NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState) + { + return NS_OK; + } // nsIContent NS_IMETHOD SetParent(nsIContent *aParent); @@ -662,8 +638,14 @@ public: NS_IMETHOD GetForm(nsIDOMHTMLFormElement** aForm); NS_IMETHOD SetForm(nsIDOMHTMLFormElement* aForm, PRBool aRemoveFromForm = PR_TRUE); - NS_IMETHOD SaveState() { return NS_OK; } - NS_IMETHOD RestoreState(nsIPresState* aState) { return NS_OK; } + NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState) + { + return NS_OK; + } + NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState) + { + return NS_OK; + } // nsIContent NS_IMETHOD SetParent(nsIContent *aParent); @@ -676,7 +658,7 @@ public: NS_IMETHOD SetAttr(nsINodeInfo* aNodeInfo, const nsAString& aValue, PRBool aNotify); - NS_IMETHOD DoneCreatingElement(); + NS_METHOD SetAttribute(const nsAString& aName, const nsAString& aValue) @@ -967,8 +949,7 @@ nsresult NS_NewHTMLImageElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo); nsresult -NS_NewHTMLInputElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser); +NS_NewHTMLInputElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo); nsresult NS_NewHTMLInsElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo); @@ -1034,8 +1015,7 @@ nsresult NS_NewHTMLScriptElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo); nsresult -NS_NewHTMLSelectElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser); +NS_NewHTMLSelectElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo); inline nsresult NS_NewHTMLSpacerElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo) diff --git a/mozilla/content/html/content/src/nsHTMLInputElement.cpp b/mozilla/content/html/content/src/nsHTMLInputElement.cpp index 5cb3fe7e15d..bb30e5eb5d5 100644 --- a/mozilla/content/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLInputElement.cpp @@ -1,3 +1,4 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * @@ -118,8 +119,6 @@ typedef nsIGfxTextControlFrame2 textControlPlace; #define BF_CHECKED_CHANGED 3 #define BF_CHECKED 4 #define BF_HANDLING_SELECT_EVENT 5 -#define BF_SHOULD_INIT_CHECKED 6 -#define BF_PARSER_CREATING 7 #define GET_BOOLBIT(bitfield, field) (((bitfield) & (0x01 << (field))) \ ? PR_TRUE : PR_FALSE) @@ -134,7 +133,7 @@ class nsHTMLInputElement : public nsGenericHTMLLeafFormElement, public nsIRadioControlElement { public: - nsHTMLInputElement(PRBool aFromParser); + nsHTMLInputElement(); virtual ~nsHTMLInputElement(); // nsISupports @@ -162,8 +161,8 @@ public: NS_IMETHOD Reset(); NS_IMETHOD SubmitNamesValues(nsIFormSubmission* aFormSubmission, nsIContent* aSubmitElement); - NS_IMETHOD SaveState(); - NS_IMETHOD RestoreState(nsIPresState* aState); + NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState); + NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState); // nsIContent NS_IMETHOD SetFocus(nsIPresContext* aPresContext); @@ -213,8 +212,6 @@ public: return rv; } - NS_IMETHOD DoneCreatingElement(); - // nsITextControlElement NS_IMETHOD SetValueGuaranteed(const nsAString& aValue, nsIGfxTextControlFrame2* aFrame); NS_IMETHOD SetValueChanged(PRBool aValueChanged); @@ -229,6 +226,7 @@ public: protected: // Helper method + void SetPresStateChecked(nsIHTMLContent * aHTMLContent, PRBool aValue); NS_IMETHOD SetValueSecure(const nsAString& aValue, nsIGfxTextControlFrame2* aFrame, PRBool aCheckSecurity); @@ -312,12 +310,11 @@ NS_METHOD NS_GetRadioGetCheckedChangedVisitor(PRBool* aCheckedChanged, nsresult NS_NewHTMLInputElement(nsIHTMLContent** aInstancePtrResult, - nsINodeInfo *aNodeInfo, - PRBool aFromParser) + nsINodeInfo *aNodeInfo) { NS_ENSURE_ARG_POINTER(aInstancePtrResult); - nsHTMLInputElement* it = new nsHTMLInputElement(aFromParser); + nsHTMLInputElement* it = new nsHTMLInputElement(); if (!it) { return NS_ERROR_OUT_OF_MEMORY; @@ -338,11 +335,10 @@ NS_NewHTMLInputElement(nsIHTMLContent** aInstancePtrResult, } -nsHTMLInputElement::nsHTMLInputElement(PRBool aFromParser) +nsHTMLInputElement::nsHTMLInputElement() { mType = NS_FORM_INPUT_TEXT; // default value mBitField = 0; - SET_BOOLBIT(mBitField, BF_PARSER_CREATING, aFromParser); mValue = nsnull; } @@ -382,7 +378,7 @@ nsHTMLInputElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) NS_ENSURE_ARG_POINTER(aReturn); *aReturn = nsnull; - nsHTMLInputElement* it = new nsHTMLInputElement(PR_FALSE); + nsHTMLInputElement* it = new nsHTMLInputElement(); if (!it) { return NS_ERROR_OUT_OF_MEMORY; @@ -456,16 +452,10 @@ nsHTMLInputElement::AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, // if (aName == nsHTMLAtoms::checked && !GET_BOOLBIT(mBitField, BF_CHECKED_CHANGED)) { - // Delay setting checked if the parser is creating this element (wait until - // everything is set) - if (GET_BOOLBIT(mBitField, BF_PARSER_CREATING)) { - SET_BOOLBIT(mBitField, BF_SHOULD_INIT_CHECKED, PR_TRUE); - } else { - PRBool defaultChecked; - GetDefaultChecked(&defaultChecked); - SetChecked(defaultChecked); - SetCheckedChanged(PR_FALSE); - } + PRBool resetVal; + GetDefaultChecked(&resetVal); + SetChecked(resetVal); + SetCheckedChanged(PR_FALSE); } } @@ -626,7 +616,6 @@ nsHTMLInputElement::SetValueSecure(const nsAString& aValue, GetType(&type); if (NS_FORM_INPUT_TEXT == type || NS_FORM_INPUT_PASSWORD == type || NS_FORM_INPUT_FILE == type) { - if (aCheckSecurity && NS_FORM_INPUT_FILE == type) { nsresult rv; nsCOMPtr securityManager = @@ -648,6 +637,7 @@ nsHTMLInputElement::SetValueSecure(const nsAString& aValue, } } + nsIGfxTextControlFrame2* textControlFrame = aFrame; nsIFormControlFrame* formControlFrame = textControlFrame; if (!textControlFrame) { @@ -661,12 +651,7 @@ nsHTMLInputElement::SetValueSecure(const nsAString& aValue, } } - // File frames always own the value (if the frame is there). - // Text frames have a bit that says whether they own the value. PRBool frameOwnsValue = PR_FALSE; - if (type == NS_FORM_INPUT_FILE && formControlFrame) { - frameOwnsValue = PR_TRUE; - } if (textControlFrame) { textControlFrame->OwnsValue(&frameOwnsValue); } @@ -714,6 +699,20 @@ nsHTMLInputElement::GetChecked(PRBool* aChecked) return NS_OK; } +void +nsHTMLInputElement::SetPresStateChecked(nsIHTMLContent * aHTMLContent, + PRBool aValue) +{ + nsCOMPtr presState; + GetPrimaryPresState(aHTMLContent, getter_AddRefs(presState)); + + // Obtain the value property from the presentation state. + if (presState) { + nsAutoString value; value.AssignWithConversion( aValue ? "1" : "0" ); + presState->SetStateProperty(NS_LITERAL_STRING("checked"), value); + } +} + NS_IMETHODIMP nsHTMLInputElement::SetCheckedChanged(PRBool aCheckedChanged) { @@ -1598,9 +1597,8 @@ nsHTMLInputElement::StringToAttribute(nsIAtom* aAttribute, if (valueStr.EqualsIgnoreCase(table->tag)) { // If the type is being changed to file, set the element value // to the empty string. This is for security. - if (table->value == NS_FORM_INPUT_FILE) { + if (table->value == NS_FORM_INPUT_FILE) SetValue(NS_LITERAL_STRING("")); - } aResult.SetIntValue(table->value, eHTMLUnit_Enumerated); mType = table->value; // set the type of this input return NS_CONTENT_ATTR_HAS_VALUE; @@ -2011,7 +2009,7 @@ nsHTMLInputElement::Reset() case NS_FORM_INPUT_FILE: { // Resetting it to blank should not perform security check - rv = SetValueGuaranteed(NS_LITERAL_STRING(""), nsnull); + rv = SetValueSecure(NS_LITERAL_STRING(""), nsnull, PR_FALSE); break; } default: @@ -2236,37 +2234,30 @@ nsHTMLInputElement::SubmitNamesValues(nsIFormSubmission* aFormSubmission, NS_IMETHODIMP -nsHTMLInputElement::SaveState() +nsHTMLInputElement::SaveState(nsIPresContext* aPresContext, + nsIPresState** aState) { nsresult rv = NS_OK; PRInt32 type; GetType(&type); - nsCOMPtr state; switch (type) { case NS_FORM_INPUT_CHECKBOX: case NS_FORM_INPUT_RADIO: { PRBool checked = PR_FALSE; GetChecked(&checked); - PRBool defaultChecked = PR_FALSE; - GetDefaultChecked(&defaultChecked); - // Only save if checked != defaultChecked (bug 62713) - // (always save if it's a radio button so that the checked - // state of all radio buttons is restored) - if (type == NS_FORM_INPUT_RADIO || checked != defaultChecked) { - rv = GetPrimaryPresState(this, getter_AddRefs(state)); - if (state) { - if (checked) { - rv = state->SetStateProperty(NS_LITERAL_STRING("checked"), - NS_LITERAL_STRING("t")); - } else { - rv = state->SetStateProperty(NS_LITERAL_STRING("checked"), - NS_LITERAL_STRING("f")); - } - NS_ASSERTION(NS_SUCCEEDED(rv), "checked save failed!"); + rv = GetPrimaryPresState(this, aState); + if (*aState) { + if (checked) { + rv = (*aState)->SetStateProperty(NS_LITERAL_STRING("checked"), + NS_LITERAL_STRING("t")); + } else { + rv = (*aState)->SetStateProperty(NS_LITERAL_STRING("checked"), + NS_LITERAL_STRING("f")); } + NS_ASSERTION(NS_SUCCEEDED(rv), "checked save failed!"); } break; } @@ -2277,19 +2268,19 @@ nsHTMLInputElement::SaveState() case NS_FORM_INPUT_TEXT: case NS_FORM_INPUT_FILE: { - if (GET_BOOLBIT(mBitField, BF_VALUE_CHANGED)) { - rv = GetPrimaryPresState(this, getter_AddRefs(state)); - if (state) { - nsAutoString value; - GetValue(value); - rv = nsLinebreakConverter::ConvertStringLineBreaks( - value, - nsLinebreakConverter::eLinebreakPlatform, - nsLinebreakConverter::eLinebreakContent); - NS_ASSERTION(NS_SUCCEEDED(rv), "Converting linebreaks failed!"); - rv = state->SetStateProperty(NS_LITERAL_STRING("v"), value); - NS_ASSERTION(NS_SUCCEEDED(rv), "value save failed!"); - } + nsresult rv = GetPrimaryPresState(this, aState); + if (*aState) { + nsString value; + GetValue(value); + // XXX Should use nsAutoString above but ConvertStringLineBreaks + // requires mOwnsBuffer! + rv = nsLinebreakConverter::ConvertStringLineBreaks( + value, + nsLinebreakConverter::eLinebreakPlatform, + nsLinebreakConverter::eLinebreakContent); + NS_ASSERTION(NS_SUCCEEDED(rv), "Converting linebreaks failed!"); + rv = (*aState)->SetStateProperty(NS_LITERAL_STRING("value"), value); + NS_ASSERTION(NS_SUCCEEDED(rv), "value save failed!"); } break; } @@ -2299,41 +2290,8 @@ nsHTMLInputElement::SaveState() } NS_IMETHODIMP -nsHTMLInputElement::DoneCreatingElement() -{ - SET_BOOLBIT(mBitField, BF_PARSER_CREATING, PR_FALSE); - - // - // Restore state for checkbox, radio, text and file - // - PRBool restored = PR_FALSE; - switch (mType) { - case NS_FORM_INPUT_CHECKBOX: - case NS_FORM_INPUT_RADIO: - case NS_FORM_INPUT_TEXT: - case NS_FORM_INPUT_FILE: - restored = RestoreFormControlState(this, this); - break; - } - - // - // If restore does not occur, we initialize .checked using the CHECKED - // property. - // - if (!restored && GET_BOOLBIT(mBitField, BF_SHOULD_INIT_CHECKED)) { - PRBool resetVal; - GetDefaultChecked(&resetVal); - SetChecked(resetVal); - SetCheckedChanged(PR_FALSE); - } - - SET_BOOLBIT(mBitField, BF_SHOULD_INIT_CHECKED, PR_FALSE); - - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLInputElement::RestoreState(nsIPresState* aState) +nsHTMLInputElement::RestoreState(nsIPresContext* aPresContext, + nsIPresState* aState) { nsresult rv = NS_OK; @@ -2348,18 +2306,25 @@ nsHTMLInputElement::RestoreState(nsIPresState* aState) 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 (checked.Equals(NS_LITERAL_STRING("t"))) { + SetChecked(PR_TRUE); + } else { + SetChecked(PR_FALSE); + } break; } + // Never save passwords in session history + case NS_FORM_INPUT_PASSWORD: + break; case NS_FORM_INPUT_TEXT: case NS_FORM_INPUT_FILE: { nsAutoString value; - rv = aState->GetStateProperty(NS_LITERAL_STRING("v"), value); + rv = aState->GetStateProperty(NS_LITERAL_STRING("value"), value); NS_ASSERTION(NS_SUCCEEDED(rv), "value restore failed!"); - SetValueGuaranteed(value, nsnull); + SetValue(value); break; } } diff --git a/mozilla/content/html/content/src/nsHTMLSelectElement.cpp b/mozilla/content/html/content/src/nsHTMLSelectElement.cpp index f83497a64cd..c9b693160a5 100644 --- a/mozilla/content/html/content/src/nsHTMLSelectElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLSelectElement.cpp @@ -128,7 +128,7 @@ class nsHTMLSelectElement : public nsGenericHTMLContainerFormElement, public nsISelectElement { public: - nsHTMLSelectElement(PRBool aFromParser); + nsHTMLSelectElement(); virtual ~nsHTMLSelectElement(); // nsISupports @@ -238,7 +238,7 @@ protected: nsISelectControlFrame *GetSelectFrame(); nsHTMLOptionCollection* mOptions; - PRBool mIsDoneAddingChildren; + PRBool mIsDoneAddingContent; PRUint32 mArtifactsAtTopLevel; PRInt32 mSelectedIndex; nsString* mRestoreState; @@ -254,12 +254,11 @@ protected: nsresult NS_NewHTMLSelectElement(nsIHTMLContent** aInstancePtrResult, - nsINodeInfo *aNodeInfo, - PRBool aFromParser) + nsINodeInfo *aNodeInfo) { NS_ENSURE_ARG_POINTER(aInstancePtrResult); - nsHTMLSelectElement* it = new nsHTMLSelectElement(aFromParser); + nsHTMLSelectElement* it = new nsHTMLSelectElement(); if (!it) { return NS_ERROR_OUT_OF_MEMORY; @@ -280,11 +279,9 @@ NS_NewHTMLSelectElement(nsIHTMLContent** aInstancePtrResult, } -nsHTMLSelectElement::nsHTMLSelectElement(PRBool aFromParser) +nsHTMLSelectElement::nsHTMLSelectElement() { - // DoneAddingChildren() will be called later if it's from the parser, - // otherwise it is - mIsDoneAddingChildren = !aFromParser; + mIsDoneAddingContent = PR_TRUE; mArtifactsAtTopLevel = 0; mOptions = new nsHTMLOptionCollection(this); @@ -333,7 +330,7 @@ nsHTMLSelectElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) NS_ENSURE_ARG_POINTER(aReturn); *aReturn = nsnull; - nsHTMLSelectElement* it = new nsHTMLSelectElement(PR_FALSE); + nsHTMLSelectElement* it = new nsHTMLSelectElement(); if (!it) { return NS_ERROR_OUT_OF_MEMORY; @@ -1584,7 +1581,7 @@ nsHTMLSelectElement::NamedItem(const nsAString& aName, nsresult nsHTMLSelectElement::CheckSelectSomething() { - if (mIsDoneAddingChildren) { + if (mIsDoneAddingContent) { PRInt32 size = 1; GetSize(&size); PRBool isMultiple; @@ -1601,7 +1598,7 @@ nsresult nsHTMLSelectElement::SelectSomething() { // If we're not done building the select, don't play with this yet. - if (!mIsDoneAddingChildren) { + if (!mIsDoneAddingContent) { return NS_OK; } @@ -1645,38 +1642,33 @@ nsHTMLSelectElement::RemoveOption(nsIContent* aContent) } NS_IMETHODIMP -nsHTMLSelectElement::IsDoneAddingChildren(PRBool * aIsDone) +nsHTMLSelectElement::IsDoneAddingContent(PRBool * aIsDone) { - *aIsDone = mIsDoneAddingChildren; + *aIsDone = mIsDoneAddingContent; return NS_OK; } NS_IMETHODIMP -nsHTMLSelectElement::DoneAddingChildren() +nsHTMLSelectElement::DoneAddingContent(PRBool aIsDone) { - mIsDoneAddingChildren = PR_TRUE; + mIsDoneAddingContent = aIsDone; - nsISelectControlFrame* selectFrame = GetSelectFrame(); + nsISelectControlFrame* sFrame = GetSelectFrame(); // If we foolishly tried to restore before we were done adding // content, restore the rest of the options proper-like - if (mRestoreState) { + if (mIsDoneAddingContent && mRestoreState) { RestoreStateTo(mRestoreState); delete mRestoreState; mRestoreState = nsnull; } - // Notify the frame - if (selectFrame) { - selectFrame->DoneAddingChildren(PR_TRUE); + if (sFrame) { + sFrame->DoneAddingContent(mIsDoneAddingContent); } - // Restore state - RestoreFormControlState(this, this); - - // Now that we're done, select something (if it's a single select something - // must be selected) + // Now that we're done, select something CheckSelectSomething(); return NS_OK; @@ -1811,7 +1803,8 @@ nsHTMLSelectElement::GetType(PRInt32* aType) } NS_IMETHODIMP -nsHTMLSelectElement::SaveState() +nsHTMLSelectElement::SaveState(nsIPresContext* aPresContext, + nsIPresState** aState) { nsAutoString stateStr; @@ -1833,19 +1826,24 @@ nsHTMLSelectElement::SaveState() } } - nsCOMPtr state; - nsresult rv = GetPrimaryPresState(this, getter_AddRefs(state)); - if (state) { - rv = state->SetStateProperty(NS_LITERAL_STRING("selecteditems"), - stateStr); + nsresult rv = GetPrimaryPresState(this, aState); + if (*aState) { + rv = (*aState)->SetStateProperty(NS_LITERAL_STRING("selecteditems"), + stateStr); NS_ASSERTION(NS_SUCCEEDED(rv), "selecteditems set failed!"); } return rv; } NS_IMETHODIMP -nsHTMLSelectElement::RestoreState(nsIPresState* aState) +nsHTMLSelectElement::RestoreState(nsIPresContext* aPresContext, + nsIPresState* aState) { + // XXX This works right now, but since this is only called from + // RestoreState() in the frame, this will happen at the first frame + // creation. If JavaScript makes changes before then, and the page + // is being reloaded, these changes will be lost. + // // If RestoreState() is called a second time after SaveState() was // called, this will do nothing. @@ -1882,7 +1880,7 @@ nsHTMLSelectElement::GetBoxObject(nsIBoxObject** aResult) nsresult nsHTMLSelectElement::RestoreStateTo(nsAString* aNewSelected) { - if (!mIsDoneAddingChildren) { + if (!mIsDoneAddingContent) { mRestoreState = new nsString; if (!mRestoreState) { return NS_OK; diff --git a/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp b/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp index 1db66e30086..6c7cd29cb96 100644 --- a/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp @@ -73,7 +73,6 @@ #include "nsIDOMText.h" #include "nsReadableUtils.h" #include "nsITextContent.h" -#include "nsITextAreaElement.h" static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID); @@ -81,8 +80,7 @@ static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID); class nsHTMLTextAreaElement : public nsGenericHTMLContainerFormElement, public nsIDOMHTMLTextAreaElement, public nsIDOMNSHTMLTextAreaElement, - public nsITextControlElement, - public nsITextAreaElement + public nsITextControlElement { public: nsHTMLTextAreaElement(); @@ -106,16 +104,13 @@ public: // nsIDOMNSHTMLTextAreaElement NS_DECL_NSIDOMNSHTMLTEXTAREAELEMENT - // nsITextAreaElement - NS_DECL_NSITEXTAREAELEMENT - // nsIFormControl NS_IMETHOD GetType(PRInt32* aType); NS_IMETHOD Reset(); NS_IMETHOD SubmitNamesValues(nsIFormSubmission* aFormSubmission, nsIContent* aSubmitElement); - NS_IMETHOD SaveState(); - NS_IMETHOD RestoreState(nsIPresState* aState); + NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState); + NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState); // nsITextControlElement NS_IMETHOD SetValueGuaranteed(const nsAString& aValue, nsIGfxTextControlFrame2* aFrame); @@ -202,7 +197,6 @@ NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLTextAreaElement, NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLTextAreaElement) NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLTextAreaElement) NS_INTERFACE_MAP_ENTRY(nsITextControlElement) - NS_INTERFACE_MAP_ENTRY(nsITextAreaElement) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLTextAreaElement) NS_HTML_CONTENT_INTERFACE_MAP_END @@ -795,14 +789,6 @@ nsHTMLTextAreaElement::HandleDOMEvent(nsIPresContext* aPresContext, return rv; } -// nsITextAreaElement -NS_IMETHODIMP -nsHTMLTextAreaElement::DoneAddingChildren() -{ - RestoreFormControlState(this, this); - return NS_OK; -} - // nsIFormControl NS_IMETHODIMP @@ -928,33 +914,30 @@ nsHTMLTextAreaElement::SubmitNamesValues(nsIFormSubmission* aFormSubmission, NS_IMETHODIMP -nsHTMLTextAreaElement::SaveState() +nsHTMLTextAreaElement::SaveState(nsIPresContext* aPresContext, + nsIPresState** aState) { - nsresult rv = NS_OK; - - // Only save if value != defaultValue (bug 62713) - if (mValueChanged) { - nsCOMPtr state; - rv = GetPrimaryPresState(this, getter_AddRefs(state)); - if (state) { - nsAutoString value; - GetValue(value); - - rv = nsLinebreakConverter::ConvertStringLineBreaks( - value, - nsLinebreakConverter::eLinebreakPlatform, - nsLinebreakConverter::eLinebreakContent); - NS_ASSERTION(NS_SUCCEEDED(rv), "Converting linebreaks failed!"); - rv = state->SetStateProperty(NS_LITERAL_STRING("value"), value); - NS_ASSERTION(NS_SUCCEEDED(rv), "value save failed!"); - } + nsresult rv = GetPrimaryPresState(this, aState); + if (*aState) { + nsString value; + GetValue(value); + // XXX Should use nsAutoString above but ConvertStringLineBreaks requires + // mOwnsBuffer! + rv = nsLinebreakConverter::ConvertStringLineBreaks( + value, + nsLinebreakConverter::eLinebreakPlatform, + nsLinebreakConverter::eLinebreakContent); + NS_ASSERTION(NS_SUCCEEDED(rv), "Converting linebreaks failed!"); + rv = (*aState)->SetStateProperty(NS_LITERAL_STRING("value"), value); + NS_ASSERTION(NS_SUCCEEDED(rv), "value save failed!"); } return rv; } NS_IMETHODIMP -nsHTMLTextAreaElement::RestoreState(nsIPresState* aState) +nsHTMLTextAreaElement::RestoreState(nsIPresContext* aPresContext, + nsIPresState* aState) { nsresult rv = NS_OK; diff --git a/mozilla/content/html/document/src/nsHTMLContentSink.cpp b/mozilla/content/html/document/src/nsHTMLContentSink.cpp index a6957980559..9d4df753258 100644 --- a/mozilla/content/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLContentSink.cpp @@ -123,7 +123,6 @@ #include "nsIParserService.h" #include "nsParserCIID.h" #include "nsISelectElement.h" -#include "nsITextAreaElement.h" #include "nsIPref.h" @@ -811,9 +810,8 @@ MakeContentObject(nsHTMLTag aNodeType, nsIDOMHTMLFormElement* aForm, nsIWebShell* aWebShell, nsIHTMLContent** aResult, - const nsAString* aSkippedContent, - PRBool aInsideNoXXXTag, - PRBool aFromParser); + const nsAString* aSkippedContent = nsnull, + PRBool aInsideNoXXXTag = PR_FALSE); /** @@ -860,8 +858,7 @@ HTMLContentSink::CreateContentObject(const nsIParserNode& aNode, } // Make the content object rv = MakeContentObject(aNodeType, nodeInfo, aForm, aWebShell, - aResult, skippedContent, !!mInsideNoXXXTag, - PR_TRUE); + aResult, skippedContent, !!mInsideNoXXXTag); PRInt32 id; mDocument->GetAndIncrementContentID(&id); @@ -898,7 +895,7 @@ NS_CreateHTMLElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, if (aCaseSensitive) { rv = MakeContentObject(nsHTMLTag(id), aNodeInfo, nsnull, nsnull, - aResult, nsnull, PR_FALSE, PR_FALSE); + aResult); } else { // Revese map id to name to get the correct character case in // the tag name. @@ -925,8 +922,7 @@ NS_CreateHTMLElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, } } - rv = MakeContentObject(nsHTMLTag(id), nodeInfo, nsnull, nsnull, aResult, - nsnull, PR_FALSE, PR_FALSE); + rv = MakeContentObject(nsHTMLTag(id), nodeInfo, nsnull, nsnull, aResult); } } @@ -998,8 +994,7 @@ MakeContentObject(nsHTMLTag aNodeType, nsIWebShell* aWebShell, nsIHTMLContent** aResult, const nsAString* aSkippedContent, - PRBool aInsideNoXXXTag, - PRBool aFromParser) + PRBool aInsideNoXXXTag) { nsresult rv = NS_OK; switch (aNodeType) { @@ -1110,7 +1105,7 @@ MakeContentObject(nsHTMLTag aNodeType, rv = NS_NewHTMLImageElement(aResult, aNodeInfo); break; case eHTMLTag_input: - rv = NS_NewHTMLInputElement(aResult, aNodeInfo, aFromParser); + rv = NS_NewHTMLInputElement(aResult, aNodeInfo); if (!aInsideNoXXXTag) SetForm(*aResult, aForm); break; @@ -1175,7 +1170,7 @@ MakeContentObject(nsHTMLTag aNodeType, rv = NS_NewHTMLScriptElement(aResult, aNodeInfo); break; case eHTMLTag_select: - rv = NS_NewHTMLSelectElement(aResult, aNodeInfo, aFromParser); + rv = NS_NewHTMLSelectElement(aResult, aNodeInfo); if (!aInsideNoXXXTag) { SetForm(*aResult, aForm); } @@ -1426,6 +1421,13 @@ SinkContext::OpenContainer(const nsIParserNode& aNode) return rv; } + if (nodeType == eHTMLTag_select) { + nsCOMPtr select(do_QueryInterface(content)); + if (select) { + select->DoneAddingContent(PR_FALSE); + } + } + mStack[mStackPos].mType = nodeType; mStack[mStackPos].mContent = content; mStack[mStackPos].mFlags = 0; @@ -1605,8 +1607,9 @@ SinkContext::CloseContainer(const nsIParserNode& aNode) case eHTMLTag_select: { nsCOMPtr select = do_QueryInterface(content, &result); - if (select) { - result = select->DoneAddingChildren(); + + if (NS_SUCCEEDED(result)) { + result = select->DoneAddingContent(PR_TRUE); } } break; @@ -1881,22 +1884,6 @@ SinkContext::AddLeaf(const nsIParserNode& aNode) // Add new leaf to its parent AddLeaf(content); - - // Notify input and button that they are now fully created - switch (nodeType) { - case eHTMLTag_input: - case eHTMLTag_button: - content->DoneCreatingElement(); - break; - case eHTMLTag_textarea: - // XXX textarea deserves to be treated like the container it is. - nsCOMPtr textarea(do_QueryInterface(content)); - if (textarea) { - textarea->DoneAddingChildren(); - } - break; - } - NS_RELEASE(content); } break; diff --git a/mozilla/content/macbuild/contentIDL.xml b/mozilla/content/macbuild/contentIDL.xml index c1679539c79..cc02a85bf7f 100644 --- a/mozilla/content/macbuild/contentIDL.xml +++ b/mozilla/content/macbuild/contentIDL.xml @@ -869,13 +869,6 @@ Text - - Name - nsITextAreaElement.idl - MacOS - Text - - Name nsIWyciwygChannel.idl @@ -984,11 +977,6 @@ nsISelectElement.idl MacOS - - Name - nsITextAreaElement.idl - MacOS - Name nsIWyciwygChannel.idl @@ -1822,13 +1810,6 @@ Text - - Name - nsITextAreaElement.idl - MacOS - Text - - Name nsIWyciwygChannel.idl @@ -1937,11 +1918,6 @@ nsISelectElement.idl MacOS - - Name - nsITextAreaElement.idl - MacOS - Name nsIWyciwygChannel.idl @@ -2069,12 +2045,6 @@ nsISelectElement.idl MacOS - - headers - Name - nsITextAreaElement.idl - MacOS - headers Name diff --git a/mozilla/content/xul/content/src/nsXULElement.cpp b/mozilla/content/xul/content/src/nsXULElement.cpp index 468fbdbd2f0..079e5210435 100644 --- a/mozilla/content/xul/content/src/nsXULElement.cpp +++ b/mozilla/content/xul/content/src/nsXULElement.cpp @@ -1880,11 +1880,6 @@ nsXULElement::HandleEvent(nsIDOMEvent *aEvent) return DispatchEvent(aEvent, &noDefault); } -NS_IMETHODIMP -nsXULElement::DoneCreatingElement() -{ - return NS_OK; -} //---------------------------------------------------------------------- // nsIScriptEventHandlerOwner interface diff --git a/mozilla/content/xul/content/src/nsXULElement.h b/mozilla/content/xul/content/src/nsXULElement.h index c64173eb132..5cbc1084f9d 100644 --- a/mozilla/content/xul/content/src/nsXULElement.h +++ b/mozilla/content/xul/content/src/nsXULElement.h @@ -389,7 +389,6 @@ public: nsIDOMEvent** aDOMEvent, PRUint32 aFlags, nsEventStatus* aEventStatus); - NS_IMETHOD DoneCreatingElement(); NS_IMETHOD GetContentID(PRUint32* aID); NS_IMETHOD SetContentID(PRUint32 aID); diff --git a/mozilla/layout/base/nsFrameManager.cpp b/mozilla/layout/base/nsFrameManager.cpp index cfcb8f660e2..6722328e9a5 100644 --- a/mozilla/layout/base/nsFrameManager.cpp +++ b/mozilla/layout/base/nsFrameManager.cpp @@ -71,7 +71,6 @@ #include "nsIContentList.h" #include "nsReadableUtils.h" #include "nsUnicharUtils.h" -#include "nsPrintfCString.h" #ifdef DEBUG #undef NOISY_DEBUG @@ -367,7 +366,7 @@ public: nsIStatefulFrame::SpecialStateID aID = nsIStatefulFrame::eNoID); NS_IMETHOD GenerateStateKey(nsIContent* aContent, nsIStatefulFrame::SpecialStateID aID, - nsACString& aString); + nsCString& aString); // Gets and sets properties on a given frame NS_IMETHOD GetFrameProperty(nsIFrame* aFrame, @@ -2049,14 +2048,14 @@ FrameManager::RestoreFrameState(nsIPresContext* aPresContext, nsIFrame* aFrame, } -static inline void KeyAppendSep(nsACString& aKey) +static inline void KeyAppendSep(nsCString& aKey) { if (!aKey.IsEmpty()) { - aKey.Append('>'); + aKey.Append(">"); } } -static inline void KeyAppendString(const nsAString& aString, nsACString& aKey) +static inline void KeyAppendString(const nsAString& aString, nsCString& aKey) { KeyAppendSep(aKey); @@ -2066,14 +2065,14 @@ static inline void KeyAppendString(const nsAString& aString, nsACString& aKey) aKey.Append(NS_ConvertUCS2toUTF8(aString)); } -static inline void KeyAppendInt(PRInt32 aInt, nsACString& aKey) +static inline void KeyAppendInt(PRInt32 aInt, nsCString& aKey) { KeyAppendSep(aKey); - aKey.Append(nsPrintfCString("%d", aInt)); + aKey.AppendInt(aInt); } -static inline void KeyAppendAtom(nsIAtom* aAtom, nsACString& aKey) +static inline void KeyAppendAtom(nsIAtom* aAtom, nsCString& aKey) { NS_PRECONDITION(aAtom, "KeyAppendAtom: aAtom can not be null!\n"); @@ -2094,7 +2093,7 @@ static inline PRBool IsAutocompleteOff(nsIDOMElement* aElement) NS_IMETHODIMP FrameManager::GenerateStateKey(nsIContent* aContent, nsIStatefulFrame::SpecialStateID aID, - nsACString& aKey) + nsCString& aKey) { aKey.Truncate(); diff --git a/mozilla/layout/base/public/nsIFrameManager.h b/mozilla/layout/base/public/nsIFrameManager.h index 257deeacbf1..8f3f4ccec68 100644 --- a/mozilla/layout/base/public/nsIFrameManager.h +++ b/mozilla/layout/base/public/nsIFrameManager.h @@ -202,7 +202,7 @@ public: nsIStatefulFrame::SpecialStateID aID = nsIStatefulFrame::eNoID) = 0; NS_IMETHOD GenerateStateKey(nsIContent* aContent, nsIStatefulFrame::SpecialStateID aID, - nsACString& aString) = 0; + nsCString& aString) = 0; /** diff --git a/mozilla/layout/forms/nsComboboxControlFrame.cpp b/mozilla/layout/forms/nsComboboxControlFrame.cpp index 564fb28ad4f..080ac754819 100644 --- a/mozilla/layout/forms/nsComboboxControlFrame.cpp +++ b/mozilla/layout/forms/nsComboboxControlFrame.cpp @@ -1872,6 +1872,7 @@ nsComboboxControlFrame::GetDropDown(nsIFrame** aDropDownFrame) NS_IMETHODIMP nsComboboxControlFrame::ToggleList(nsIPresContext* aPresContext) { + ShowList(aPresContext, (PR_FALSE == mDroppedDown)); return NS_OK; @@ -1995,7 +1996,7 @@ nsComboboxControlFrame::GetIndexOfDisplayArea(PRInt32* aSelectedIndex) // nsISelectControlFrame //---------------------------------------------------------------------- NS_IMETHODIMP -nsComboboxControlFrame::DoneAddingChildren(PRBool aIsDone) +nsComboboxControlFrame::DoneAddingContent(PRBool aIsDone) { nsISelectControlFrame* listFrame = nsnull; nsresult rv = NS_ERROR_FAILURE; @@ -2003,7 +2004,7 @@ nsComboboxControlFrame::DoneAddingChildren(PRBool aIsDone) rv = mDropdownFrame->QueryInterface(NS_GET_IID(nsISelectControlFrame), (void**)&listFrame); if (NS_SUCCEEDED(rv) && listFrame) { - rv = listFrame->DoneAddingChildren(aIsDone); + rv = listFrame->DoneAddingContent(aIsDone); NS_RELEASE(listFrame); } } @@ -2671,7 +2672,6 @@ nsComboboxControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState) { nsCOMPtr stateful(do_QueryInterface(mListControlFrame)); - NS_ASSERTION(stateful, "Couldn't cast list frame to stateful frame!!!"); if (stateful) { return stateful->SaveState(aPresContext, aState); } @@ -2689,5 +2689,6 @@ nsComboboxControlFrame::RestoreState(nsIPresContext* aPresContext, nsresult rv = CallQueryInterface(mListControlFrame, &stateful); NS_ASSERTION(NS_SUCCEEDED(rv), "Must implement nsIStatefulFrame"); rv = stateful->RestoreState(aPresContext, aState); + InitTextStr(); return rv; } diff --git a/mozilla/layout/forms/nsComboboxControlFrame.h b/mozilla/layout/forms/nsComboboxControlFrame.h index cf286d7237c..6dad9aa76d6 100644 --- a/mozilla/layout/forms/nsComboboxControlFrame.h +++ b/mozilla/layout/forms/nsComboboxControlFrame.h @@ -188,7 +188,7 @@ public: NS_IMETHOD AddOption(nsIPresContext* aPresContext, PRInt32 index); NS_IMETHOD RemoveOption(nsIPresContext* aPresContext, PRInt32 index); NS_IMETHOD GetOptionSelected(PRInt32 aIndex, PRBool* aValue); - NS_IMETHOD DoneAddingChildren(PRBool aIsDone); + NS_IMETHOD DoneAddingContent(PRBool aIsDone); NS_IMETHOD OnOptionSelected(nsIPresContext* aPresContext, PRInt32 aIndex, PRBool aSelected); diff --git a/mozilla/layout/forms/nsFileControlFrame.cpp b/mozilla/layout/forms/nsFileControlFrame.cpp index 87911fd302d..df4cf0aaa5d 100644 --- a/mozilla/layout/forms/nsFileControlFrame.cpp +++ b/mozilla/layout/forms/nsFileControlFrame.cpp @@ -63,6 +63,7 @@ #include "nsIDOMMouseListener.h" #include "nsIPresShell.h" #include "nsIDOMHTMLInputElement.h" +#include "nsIStatefulFrame.h" #include "nsISupportsPrimitives.h" #include "nsIComponentManager.h" #include "nsIDOMWindowInternal.h" @@ -148,16 +149,10 @@ nsFileControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext, if (NS_SUCCEEDED(rv)) { mTextContent->SetAttr(kNameSpaceID_None, nsHTMLAtoms::type, NS_LITERAL_STRING("text"), PR_FALSE); - nsCOMPtr textControl = do_QueryInterface(mTextContent); - if (textControl) { - textControl->SetDisabled(nsFormFrame::GetDisabled(this)); - // Initialize value when we create the content in case the value was set - // before we got here - nsCOMPtr fileContent = do_QueryInterface(mContent); - if (fileContent) { - nsAutoString value; - fileContent->GetValue(value); - textControl->SetValue(value); + if (nsFormFrame::GetDisabled(this)) { + nsCOMPtr textControl = do_QueryInterface(mTextContent); + if (textControl) { + textControl->SetDisabled(nsFormFrame::GetDisabled(this)); } } aChildList.AppendElement(mTextContent); @@ -204,6 +199,9 @@ nsFileControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) } else if (aIID.Equals(NS_GET_IID(nsIDOMMouseListener))) { *aInstancePtr = (void*)(nsIDOMMouseListener*) this; return NS_OK; + } else if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) { + *aInstancePtr = (void*)(nsIStatefulFrame*) this; + return NS_OK; } return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr); } @@ -680,6 +678,54 @@ nsFileControlFrame::Paint(nsIPresContext* aPresContext, return nsFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); } +//---------------------------------------------------------------------- +// nsIStatefulFrame +//---------------------------------------------------------------------- +NS_IMETHODIMP +nsFileControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState) +{ + NS_ENSURE_ARG_POINTER(aState); + + // Don't save state before we are initialized + if (!mTextFrame && !mCachedState) { + return NS_OK; + } + + // Get the value string + nsAutoString stateString; + nsresult res = GetProperty(nsHTMLAtoms::value, stateString); + NS_ENSURE_SUCCESS(res, res); + + // Compare to default value, and only save if needed (Bug 62713) + nsAutoString defaultStateString; + nsCOMPtr formControl(do_QueryInterface(mContent)); + if (formControl) { + formControl->GetDefaultValue(defaultStateString); + } + + if (! stateString.Equals(defaultStateString)) { + + // Construct a pres state and store value in it. + res = NS_NewPresState(aState); + NS_ENSURE_SUCCESS(res, res); + res = (*aState)->SetStateProperty(NS_LITERAL_STRING("value"), stateString); + } + + return res; +} + +NS_IMETHODIMP +nsFileControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState) +{ + NS_ENSURE_ARG_POINTER(aState); + + nsAutoString string; + aState->GetStateProperty(NS_LITERAL_STRING("value"), string); + SetProperty(aPresContext, nsHTMLAtoms::value, string); + + return NS_OK; +} + NS_IMETHODIMP nsFileControlFrame::OnContentReset() { diff --git a/mozilla/layout/forms/nsFileControlFrame.h b/mozilla/layout/forms/nsFileControlFrame.h index 56bfd7833d3..7c21d161089 100644 --- a/mozilla/layout/forms/nsFileControlFrame.h +++ b/mozilla/layout/forms/nsFileControlFrame.h @@ -42,6 +42,7 @@ #include "nsIFormControlFrame.h" #include "nsIDOMMouseListener.h" #include "nsIAnonymousContentCreator.h" +#include "nsIStatefulFrame.h" #include "nsCOMPtr.h" #include "nsIHTMLContent.h" @@ -56,7 +57,9 @@ class nsISupportsArray; class nsFileControlFrame : public nsAreaFrame, public nsIFormControlFrame, public nsIDOMMouseListener, - public nsIAnonymousContentCreator + public nsIAnonymousContentCreator, + public nsIStatefulFrame + { public: nsFileControlFrame(); @@ -180,6 +183,10 @@ public: NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; } + //nsIStatefulFrame + NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState); + NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState); + protected: virtual PRIntn GetSkipSides() const; diff --git a/mozilla/layout/forms/nsFormControlHelper.cpp b/mozilla/layout/forms/nsFormControlHelper.cpp index 35a8406481a..763b8a94504 100644 --- a/mozilla/layout/forms/nsFormControlHelper.cpp +++ b/mozilla/layout/forms/nsFormControlHelper.cpp @@ -892,3 +892,37 @@ nsFormControlHelper::Reset(nsIFrame* aFrame, nsIPresContext* aPresContext) return NS_ERROR_FAILURE; } +nsresult +nsFormControlHelper::SaveContentState(nsIFrame* aFrame, + nsIPresContext* aPresContext, + nsIPresState** aState) +{ + nsCOMPtr controlContent; + aFrame->GetContent(getter_AddRefs(controlContent)); + + nsCOMPtr control = do_QueryInterface(controlContent); + if (control) { + control->SaveState(aPresContext, aState); + return NS_OK; + } + + return NS_ERROR_FAILURE; +} + +nsresult +nsFormControlHelper::RestoreContentState(nsIFrame* aFrame, + nsIPresContext* aPresContext, + nsIPresState* aState) +{ + nsCOMPtr controlContent; + aFrame->GetContent(getter_AddRefs(controlContent)); + + nsCOMPtr control = do_QueryInterface(controlContent); + if (control) { + control->RestoreState(aPresContext, aState); + return NS_OK; + } + + NS_NOTREACHED("no content"); + return NS_ERROR_FAILURE; +} diff --git a/mozilla/layout/forms/nsFormControlHelper.h b/mozilla/layout/forms/nsFormControlHelper.h index cfe795743fc..f5f8bec6a40 100644 --- a/mozilla/layout/forms/nsFormControlHelper.h +++ b/mozilla/layout/forms/nsFormControlHelper.h @@ -160,6 +160,12 @@ public: static nsresult GetName(nsIContent* aContent, nsAString* aResult); static nsresult GetInputElementValue(nsIContent* aContent, nsString* aText, PRBool aInitialValue); static nsresult Reset(nsIFrame* aFrame, nsIPresContext* aPresContext); + static nsresult SaveContentState(nsIFrame* aFrame, + nsIPresContext* aPresContext, + nsIPresState** aState); + static nsresult RestoreContentState(nsIFrame* aFrame, + nsIPresContext* aPresContext, + nsIPresState* aState); /** * Utility to convert a string to a PRBool diff --git a/mozilla/layout/forms/nsGfxButtonControlFrame.cpp b/mozilla/layout/forms/nsGfxButtonControlFrame.cpp index 0945f49b119..562c2b824bc 100644 --- a/mozilla/layout/forms/nsGfxButtonControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxButtonControlFrame.cpp @@ -466,6 +466,8 @@ nsGfxButtonControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) if (aIID.Equals(NS_GET_IID(nsIAnonymousContentCreator))) { *aInstancePtr = NS_STATIC_CAST(nsIAnonymousContentCreator*, this); + } else if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) { + *aInstancePtr = NS_STATIC_CAST(nsIStatefulFrame*, this); } else { return nsHTMLButtonControlFrame::QueryInterface(aIID, aInstancePtr); @@ -649,3 +651,48 @@ nsGfxButtonControlFrame::HandleEvent(nsIPresContext* aPresContext, return NS_OK; } + +//---------------------------------------------------------------------- +// nsIStatefulFrame +//---------------------------------------------------------------------- +NS_IMETHODIMP +nsGfxButtonControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState) +{ + NS_ENSURE_ARG_POINTER(aState); + + // Get the value string + nsAutoString stateString; + nsresult res = GetProperty(nsHTMLAtoms::value, stateString); + NS_ENSURE_SUCCESS(res, res); + + // Compare to default value, and only save if needed (Bug 62713) + NS_ENSURE_TRUE(mContent->IsContentOfType(nsIContent::eHTML_FORM_CONTROL), + NS_ERROR_UNEXPECTED); + nsAutoString defaultStateString; + if (!mDefaultValueWasChanged) { + mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::value, defaultStateString); + } + + if (mDefaultValueWasChanged || !stateString.Equals(defaultStateString)) { + + // Construct a pres state and store value in it. + res = NS_NewPresState(aState); + NS_ENSURE_SUCCESS(res, res); + res = (*aState)->SetStateProperty(NS_LITERAL_STRING("value"), stateString); + } + + return res; +} + +NS_IMETHODIMP +nsGfxButtonControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState) +{ + NS_ENSURE_ARG_POINTER(aState); + + // Set the value to the stored state. + nsAutoString stateString; + nsresult res = aState->GetStateProperty(NS_LITERAL_STRING("value"), stateString); + NS_ENSURE_SUCCESS(res, res); + + return SetProperty(aPresContext, nsHTMLAtoms::value, stateString); +} diff --git a/mozilla/layout/forms/nsGfxButtonControlFrame.h b/mozilla/layout/forms/nsGfxButtonControlFrame.h index 2f0b32bf4bd..cf88e5c95bc 100644 --- a/mozilla/layout/forms/nsGfxButtonControlFrame.h +++ b/mozilla/layout/forms/nsGfxButtonControlFrame.h @@ -43,6 +43,7 @@ #include "nsCOMPtr.h" #include "nsIAnonymousContentCreator.h" #include "nsITextContent.h" +#include "nsIStatefulFrame.h" #ifdef ACCESSIBILITY class nsIAccessible; @@ -56,7 +57,8 @@ class nsIAccessible; class nsIPresState; class nsGfxButtonControlFrame : public nsHTMLButtonControlFrame, - public nsIAnonymousContentCreator + public nsIAnonymousContentCreator, + public nsIStatefulFrame { public: nsGfxButtonControlFrame(); @@ -115,6 +117,10 @@ protected: virtual PRBool IsSubmit(PRInt32 type); virtual PRBool IsBrowse(PRInt32 type); // Browse button of file input + //nsIStatefulFrame + NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState); + NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState); + private: NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; } NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; } diff --git a/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp b/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp index 86a36c4a4ba..a0de56439aa 100644 --- a/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp @@ -96,7 +96,10 @@ nsGfxCheckboxControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr NS_ASSERTION(aInstancePtr, "QueryInterface requires a non-NULL destination!"); if ( !aInstancePtr ) return NS_ERROR_NULL_POINTER; - + if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) { + *aInstancePtr = (void*)(nsIStatefulFrame*) this; + return NS_OK; + } if (aIID.Equals(NS_GET_IID(nsICheckboxControlFrame))) { *aInstancePtr = (void*) ((nsICheckboxControlFrame*) this); return NS_OK; @@ -272,6 +275,21 @@ nsGfxCheckboxControlFrame::GetCheckboxState ( ) return retval; } +//---------------------------------------------------------------------- +// nsIStatefulFrame +//---------------------------------------------------------------------- +NS_IMETHODIMP nsGfxCheckboxControlFrame::SaveState(nsIPresContext* aPresContext, + nsIPresState** aState) +{ + return nsFormControlHelper::SaveContentState(this, aPresContext, aState); +} + +NS_IMETHODIMP nsGfxCheckboxControlFrame::RestoreState(nsIPresContext* aPresContext, + nsIPresState* aState) +{ + return nsFormControlHelper::RestoreContentState(this, aPresContext, aState); +} + //------------------------------------------------------------ // Extra Debug Methods //------------------------------------------------------------ diff --git a/mozilla/layout/forms/nsGfxCheckboxControlFrame.h b/mozilla/layout/forms/nsGfxCheckboxControlFrame.h index 80e8bd7a67e..16549d7ddd0 100644 --- a/mozilla/layout/forms/nsGfxCheckboxControlFrame.h +++ b/mozilla/layout/forms/nsGfxCheckboxControlFrame.h @@ -38,6 +38,7 @@ #define nsGfxCheckboxControlFrame_h___ #include "nsFormControlFrame.h" +#include "nsIStatefulFrame.h" #include "nsICheckboxControlFrame.h" #ifdef ACCESSIBILITY @@ -49,6 +50,7 @@ class nsIAccessible; #define NS_GFX_CHECKBOX_CONTROL_FRAME_LAST_CONTEXT_INDEX 0 class nsGfxCheckboxControlFrame : public nsFormControlFrame, + public nsIStatefulFrame, public nsICheckboxControlFrame//, //public nsIAccessible { @@ -88,7 +90,11 @@ public: // nsIFormControlFrame NS_IMETHOD OnContentReset(); + // nsIStatefulFrame NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); + NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState); + NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState); + #ifdef DEBUG_rodsXXX NS_IMETHOD Reflow(nsIPresContext* aCX, diff --git a/mozilla/layout/forms/nsGfxRadioControlFrame.cpp b/mozilla/layout/forms/nsGfxRadioControlFrame.cpp index 89f0ae2c598..5e0f9b7d33e 100644 --- a/mozilla/layout/forms/nsGfxRadioControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxRadioControlFrame.cpp @@ -94,6 +94,10 @@ nsGfxRadioControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) *aInstancePtr = (void*) ((nsIRadioControlFrame*) this); return NS_OK; } + if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) { + *aInstancePtr = (void*) ((nsIStatefulFrame*) this); + return NS_OK; + } return nsFormControlFrame::QueryInterface(aIID, aInstancePtr); } @@ -253,6 +257,25 @@ nsGfxRadioControlFrame::OnChecked(nsIPresContext* aPresContext, return NS_OK; } +//---------------------------------------------------------------------- +// nsIStatefulFrame +//---------------------------------------------------------------------- +NS_IMETHODIMP +nsGfxRadioControlFrame::SaveState(nsIPresContext* aPresContext, + nsIPresState** aState) +{ + return nsFormControlHelper::SaveContentState(this, aPresContext, aState); +} + + + +//---------------------------------------------------------------------- +NS_IMETHODIMP +nsGfxRadioControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState) +{ + return nsFormControlHelper::RestoreContentState(this, aPresContext, aState); +} + //---------------------------------------------------------------------- // Extra Debug Helper Methods diff --git a/mozilla/layout/forms/nsGfxRadioControlFrame.h b/mozilla/layout/forms/nsGfxRadioControlFrame.h index b04f5debf6d..372fbc5d6a6 100644 --- a/mozilla/layout/forms/nsGfxRadioControlFrame.h +++ b/mozilla/layout/forms/nsGfxRadioControlFrame.h @@ -39,6 +39,7 @@ #define nsGfxRadioControlFrame_h___ #include "nsFormControlFrame.h" +#include "nsIStatefulFrame.h" #include "nsIRadioControlFrame.h" #ifdef ACCESSIBILITY @@ -51,6 +52,7 @@ class nsIAccessible; #define NS_GFX_RADIO_CONTROL_FRAME_LAST_CONTEXT_INDEX 0 class nsGfxRadioControlFrame : public nsFormControlFrame, + public nsIStatefulFrame, public nsIRadioControlFrame { @@ -95,6 +97,10 @@ public: // nsIFormControlFrame NS_IMETHOD OnContentReset(); + //nsIStatefulFrame + NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState); + NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState); + ///XXX: End o the temporary methods #ifdef DEBUG_rodsXXX NS_IMETHOD Reflow(nsIPresContext* aCX, diff --git a/mozilla/layout/forms/nsISelectControlFrame.h b/mozilla/layout/forms/nsISelectControlFrame.h index 8c840ada778..aa9a701b30a 100644 --- a/mozilla/layout/forms/nsISelectControlFrame.h +++ b/mozilla/layout/forms/nsISelectControlFrame.h @@ -74,10 +74,9 @@ public: NS_IMETHOD GetOptionSelected(PRInt32 index, PRBool* value) = 0; /** - * Sets whether the parser is done adding children - * @param aIsDone whether the parser is done adding children + * Sets the select state of the option at index */ - NS_IMETHOD DoneAddingChildren(PRBool aIsDone) = 0; + NS_IMETHOD DoneAddingContent(PRBool aIsDone) = 0; /** * Notify the frame when an option is selected diff --git a/mozilla/layout/forms/nsListControlFrame.cpp b/mozilla/layout/forms/nsListControlFrame.cpp index 0dcff1613f2..96e0f9d82c4 100644 --- a/mozilla/layout/forms/nsListControlFrame.cpp +++ b/mozilla/layout/forms/nsListControlFrame.cpp @@ -553,6 +553,10 @@ nsListControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) *aInstancePtr = (void*)(nsIDOMKeyListener*) this; return NS_OK; } + if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) { + *aInstancePtr = (void*)(nsIStatefulFrame*) this; + return NS_OK; + } return nsScrollFrame::QueryInterface(aIID, aInstancePtr); } @@ -1449,7 +1453,7 @@ nsListControlFrame::SetInitialChildList(nsIPresContext* aPresContext, // First check to see if all the content has been added nsCOMPtr element(do_QueryInterface(mContent)); if (element) { - element->IsDoneAddingChildren(&mIsAllContentHere); + element->IsDoneAddingContent(&mIsAllContentHere); if (!mIsAllContentHere) { mIsAllFramesHere = PR_FALSE; mHasBeenInitialized = PR_FALSE; @@ -1965,7 +1969,7 @@ PRBool nsListControlFrame::CheckIfAllFramesHere() //------------------------------------------------------------------- NS_IMETHODIMP -nsListControlFrame::DoneAddingChildren(PRBool aIsDone) +nsListControlFrame::DoneAddingContent(PRBool aIsDone) { mIsAllContentHere = aIsDone; if (mIsAllContentHere) { @@ -1999,7 +2003,7 @@ nsListControlFrame::AddOption(nsIPresContext* aPresContext, PRInt32 aIndex) if (!mIsAllContentHere) { nsCOMPtr element(do_QueryInterface(mContent)); if (element) { - element->IsDoneAddingChildren(&mIsAllContentHere); + element->IsDoneAddingContent(&mIsAllContentHere); if (!mIsAllContentHere) { mIsAllFramesHere = PR_FALSE; mHasBeenInitialized = PR_FALSE; @@ -2771,8 +2775,15 @@ nsListControlFrame::MouseDown(nsIDOMEvent* aMouseEvent) if (NS_SUCCEEDED(mPresContext->GetEventStateManager(getter_AddRefs(stateManager)))) { nsIFrame * frame; stateManager->GetEventTarget(&frame); - if (!IsClickingInCombobox(aMouseEvent)) { - return NS_OK; + nsCOMPtr listFrame(do_QueryInterface(frame)); + if (listFrame) { + if (!IsClickingInCombobox(aMouseEvent)) { + return NS_OK; + } + } else { + if (!IsClickingInCombobox(aMouseEvent)) { + return NS_OK; + } } // This will consume the focus event we get from the clicking on the dropdown //stateManager->ConsumeFocusEvents(PR_TRUE); @@ -3564,3 +3575,21 @@ nsListControlFrame::ItemsHaveBeenRemoved(nsIPresContext * aPresContext) ResetList(aPresContext); } } + + +//-------------------------------------------------------- +// nsIStatefulFrame +//-------------------------------------------------------- +NS_IMETHODIMP +nsListControlFrame::SaveState(nsIPresContext* aPresContext, + nsIPresState** aState) +{ + return nsFormControlHelper::SaveContentState(this, aPresContext, aState); +} + +NS_IMETHODIMP +nsListControlFrame::RestoreState(nsIPresContext* aPresContext, + nsIPresState* aState) +{ + return nsFormControlHelper::RestoreContentState(this, aPresContext, aState); +} diff --git a/mozilla/layout/forms/nsListControlFrame.h b/mozilla/layout/forms/nsListControlFrame.h index e6c93e4d526..95784d6707e 100644 --- a/mozilla/layout/forms/nsListControlFrame.h +++ b/mozilla/layout/forms/nsListControlFrame.h @@ -58,6 +58,7 @@ #include "nsIPresState.h" #include "nsCWeakReference.h" #include "nsIContent.h" +#include "nsIStatefulFrame.h" class nsIDOMHTMLSelectElement; class nsIDOMHTMLCollection; @@ -67,6 +68,7 @@ class nsIViewManager; class nsIPresContext; class nsVoidArray; class nsIScrollableView; +class nsIStatefulFrame; class nsListControlFrame; class nsSelectUpdateTimer; @@ -281,7 +283,7 @@ public: NS_IMETHOD AddOption(nsIPresContext* aPresContext, PRInt32 index); NS_IMETHOD RemoveOption(nsIPresContext* aPresContext, PRInt32 index); NS_IMETHOD GetOptionSelected(PRInt32 aIndex, PRBool* aValue); - NS_IMETHOD DoneAddingChildren(PRBool aIsDone); + NS_IMETHOD DoneAddingContent(PRBool aIsDone); NS_IMETHOD OnOptionSelected(nsIPresContext* aPresContext, PRInt32 aIndex, PRBool aSelected); @@ -307,6 +309,10 @@ public: NS_IMETHOD KeyUp(nsIDOMEvent* aKeyEvent) { return NS_OK; } NS_IMETHOD KeyPress(nsIDOMEvent* aKeyEvent); + //nsIStatefulFrame + NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState); + NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState); + // Static Methods static nsIDOMHTMLSelectElement* GetSelect(nsIContent * aContent); static nsIDOMHTMLCollection* GetOptions(nsIContent * aContent, nsIDOMHTMLSelectElement* aSelect = nsnull); diff --git a/mozilla/layout/html/base/src/nsFrameManager.cpp b/mozilla/layout/html/base/src/nsFrameManager.cpp index cfcb8f660e2..6722328e9a5 100644 --- a/mozilla/layout/html/base/src/nsFrameManager.cpp +++ b/mozilla/layout/html/base/src/nsFrameManager.cpp @@ -71,7 +71,6 @@ #include "nsIContentList.h" #include "nsReadableUtils.h" #include "nsUnicharUtils.h" -#include "nsPrintfCString.h" #ifdef DEBUG #undef NOISY_DEBUG @@ -367,7 +366,7 @@ public: nsIStatefulFrame::SpecialStateID aID = nsIStatefulFrame::eNoID); NS_IMETHOD GenerateStateKey(nsIContent* aContent, nsIStatefulFrame::SpecialStateID aID, - nsACString& aString); + nsCString& aString); // Gets and sets properties on a given frame NS_IMETHOD GetFrameProperty(nsIFrame* aFrame, @@ -2049,14 +2048,14 @@ FrameManager::RestoreFrameState(nsIPresContext* aPresContext, nsIFrame* aFrame, } -static inline void KeyAppendSep(nsACString& aKey) +static inline void KeyAppendSep(nsCString& aKey) { if (!aKey.IsEmpty()) { - aKey.Append('>'); + aKey.Append(">"); } } -static inline void KeyAppendString(const nsAString& aString, nsACString& aKey) +static inline void KeyAppendString(const nsAString& aString, nsCString& aKey) { KeyAppendSep(aKey); @@ -2066,14 +2065,14 @@ static inline void KeyAppendString(const nsAString& aString, nsACString& aKey) aKey.Append(NS_ConvertUCS2toUTF8(aString)); } -static inline void KeyAppendInt(PRInt32 aInt, nsACString& aKey) +static inline void KeyAppendInt(PRInt32 aInt, nsCString& aKey) { KeyAppendSep(aKey); - aKey.Append(nsPrintfCString("%d", aInt)); + aKey.AppendInt(aInt); } -static inline void KeyAppendAtom(nsIAtom* aAtom, nsACString& aKey) +static inline void KeyAppendAtom(nsIAtom* aAtom, nsCString& aKey) { NS_PRECONDITION(aAtom, "KeyAppendAtom: aAtom can not be null!\n"); @@ -2094,7 +2093,7 @@ static inline PRBool IsAutocompleteOff(nsIDOMElement* aElement) NS_IMETHODIMP FrameManager::GenerateStateKey(nsIContent* aContent, nsIStatefulFrame::SpecialStateID aID, - nsACString& aKey) + nsCString& aKey) { aKey.Truncate(); diff --git a/mozilla/layout/html/forms/public/nsISelectControlFrame.h b/mozilla/layout/html/forms/public/nsISelectControlFrame.h index 8c840ada778..aa9a701b30a 100644 --- a/mozilla/layout/html/forms/public/nsISelectControlFrame.h +++ b/mozilla/layout/html/forms/public/nsISelectControlFrame.h @@ -74,10 +74,9 @@ public: NS_IMETHOD GetOptionSelected(PRInt32 index, PRBool* value) = 0; /** - * Sets whether the parser is done adding children - * @param aIsDone whether the parser is done adding children + * Sets the select state of the option at index */ - NS_IMETHOD DoneAddingChildren(PRBool aIsDone) = 0; + NS_IMETHOD DoneAddingContent(PRBool aIsDone) = 0; /** * Notify the frame when an option is selected diff --git a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp index 564fb28ad4f..080ac754819 100644 --- a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp @@ -1872,6 +1872,7 @@ nsComboboxControlFrame::GetDropDown(nsIFrame** aDropDownFrame) NS_IMETHODIMP nsComboboxControlFrame::ToggleList(nsIPresContext* aPresContext) { + ShowList(aPresContext, (PR_FALSE == mDroppedDown)); return NS_OK; @@ -1995,7 +1996,7 @@ nsComboboxControlFrame::GetIndexOfDisplayArea(PRInt32* aSelectedIndex) // nsISelectControlFrame //---------------------------------------------------------------------- NS_IMETHODIMP -nsComboboxControlFrame::DoneAddingChildren(PRBool aIsDone) +nsComboboxControlFrame::DoneAddingContent(PRBool aIsDone) { nsISelectControlFrame* listFrame = nsnull; nsresult rv = NS_ERROR_FAILURE; @@ -2003,7 +2004,7 @@ nsComboboxControlFrame::DoneAddingChildren(PRBool aIsDone) rv = mDropdownFrame->QueryInterface(NS_GET_IID(nsISelectControlFrame), (void**)&listFrame); if (NS_SUCCEEDED(rv) && listFrame) { - rv = listFrame->DoneAddingChildren(aIsDone); + rv = listFrame->DoneAddingContent(aIsDone); NS_RELEASE(listFrame); } } @@ -2671,7 +2672,6 @@ nsComboboxControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState) { nsCOMPtr stateful(do_QueryInterface(mListControlFrame)); - NS_ASSERTION(stateful, "Couldn't cast list frame to stateful frame!!!"); if (stateful) { return stateful->SaveState(aPresContext, aState); } @@ -2689,5 +2689,6 @@ nsComboboxControlFrame::RestoreState(nsIPresContext* aPresContext, nsresult rv = CallQueryInterface(mListControlFrame, &stateful); NS_ASSERTION(NS_SUCCEEDED(rv), "Must implement nsIStatefulFrame"); rv = stateful->RestoreState(aPresContext, aState); + InitTextStr(); return rv; } diff --git a/mozilla/layout/html/forms/src/nsComboboxControlFrame.h b/mozilla/layout/html/forms/src/nsComboboxControlFrame.h index cf286d7237c..6dad9aa76d6 100644 --- a/mozilla/layout/html/forms/src/nsComboboxControlFrame.h +++ b/mozilla/layout/html/forms/src/nsComboboxControlFrame.h @@ -188,7 +188,7 @@ public: NS_IMETHOD AddOption(nsIPresContext* aPresContext, PRInt32 index); NS_IMETHOD RemoveOption(nsIPresContext* aPresContext, PRInt32 index); NS_IMETHOD GetOptionSelected(PRInt32 aIndex, PRBool* aValue); - NS_IMETHOD DoneAddingChildren(PRBool aIsDone); + NS_IMETHOD DoneAddingContent(PRBool aIsDone); NS_IMETHOD OnOptionSelected(nsIPresContext* aPresContext, PRInt32 aIndex, PRBool aSelected); diff --git a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp index 87911fd302d..df4cf0aaa5d 100644 --- a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp @@ -63,6 +63,7 @@ #include "nsIDOMMouseListener.h" #include "nsIPresShell.h" #include "nsIDOMHTMLInputElement.h" +#include "nsIStatefulFrame.h" #include "nsISupportsPrimitives.h" #include "nsIComponentManager.h" #include "nsIDOMWindowInternal.h" @@ -148,16 +149,10 @@ nsFileControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext, if (NS_SUCCEEDED(rv)) { mTextContent->SetAttr(kNameSpaceID_None, nsHTMLAtoms::type, NS_LITERAL_STRING("text"), PR_FALSE); - nsCOMPtr textControl = do_QueryInterface(mTextContent); - if (textControl) { - textControl->SetDisabled(nsFormFrame::GetDisabled(this)); - // Initialize value when we create the content in case the value was set - // before we got here - nsCOMPtr fileContent = do_QueryInterface(mContent); - if (fileContent) { - nsAutoString value; - fileContent->GetValue(value); - textControl->SetValue(value); + if (nsFormFrame::GetDisabled(this)) { + nsCOMPtr textControl = do_QueryInterface(mTextContent); + if (textControl) { + textControl->SetDisabled(nsFormFrame::GetDisabled(this)); } } aChildList.AppendElement(mTextContent); @@ -204,6 +199,9 @@ nsFileControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) } else if (aIID.Equals(NS_GET_IID(nsIDOMMouseListener))) { *aInstancePtr = (void*)(nsIDOMMouseListener*) this; return NS_OK; + } else if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) { + *aInstancePtr = (void*)(nsIStatefulFrame*) this; + return NS_OK; } return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr); } @@ -680,6 +678,54 @@ nsFileControlFrame::Paint(nsIPresContext* aPresContext, return nsFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); } +//---------------------------------------------------------------------- +// nsIStatefulFrame +//---------------------------------------------------------------------- +NS_IMETHODIMP +nsFileControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState) +{ + NS_ENSURE_ARG_POINTER(aState); + + // Don't save state before we are initialized + if (!mTextFrame && !mCachedState) { + return NS_OK; + } + + // Get the value string + nsAutoString stateString; + nsresult res = GetProperty(nsHTMLAtoms::value, stateString); + NS_ENSURE_SUCCESS(res, res); + + // Compare to default value, and only save if needed (Bug 62713) + nsAutoString defaultStateString; + nsCOMPtr formControl(do_QueryInterface(mContent)); + if (formControl) { + formControl->GetDefaultValue(defaultStateString); + } + + if (! stateString.Equals(defaultStateString)) { + + // Construct a pres state and store value in it. + res = NS_NewPresState(aState); + NS_ENSURE_SUCCESS(res, res); + res = (*aState)->SetStateProperty(NS_LITERAL_STRING("value"), stateString); + } + + return res; +} + +NS_IMETHODIMP +nsFileControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState) +{ + NS_ENSURE_ARG_POINTER(aState); + + nsAutoString string; + aState->GetStateProperty(NS_LITERAL_STRING("value"), string); + SetProperty(aPresContext, nsHTMLAtoms::value, string); + + return NS_OK; +} + NS_IMETHODIMP nsFileControlFrame::OnContentReset() { diff --git a/mozilla/layout/html/forms/src/nsFileControlFrame.h b/mozilla/layout/html/forms/src/nsFileControlFrame.h index 56bfd7833d3..7c21d161089 100644 --- a/mozilla/layout/html/forms/src/nsFileControlFrame.h +++ b/mozilla/layout/html/forms/src/nsFileControlFrame.h @@ -42,6 +42,7 @@ #include "nsIFormControlFrame.h" #include "nsIDOMMouseListener.h" #include "nsIAnonymousContentCreator.h" +#include "nsIStatefulFrame.h" #include "nsCOMPtr.h" #include "nsIHTMLContent.h" @@ -56,7 +57,9 @@ class nsISupportsArray; class nsFileControlFrame : public nsAreaFrame, public nsIFormControlFrame, public nsIDOMMouseListener, - public nsIAnonymousContentCreator + public nsIAnonymousContentCreator, + public nsIStatefulFrame + { public: nsFileControlFrame(); @@ -180,6 +183,10 @@ public: NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; } + //nsIStatefulFrame + NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState); + NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState); + protected: virtual PRIntn GetSkipSides() const; diff --git a/mozilla/layout/html/forms/src/nsFormControlHelper.cpp b/mozilla/layout/html/forms/src/nsFormControlHelper.cpp index 35a8406481a..763b8a94504 100644 --- a/mozilla/layout/html/forms/src/nsFormControlHelper.cpp +++ b/mozilla/layout/html/forms/src/nsFormControlHelper.cpp @@ -892,3 +892,37 @@ nsFormControlHelper::Reset(nsIFrame* aFrame, nsIPresContext* aPresContext) return NS_ERROR_FAILURE; } +nsresult +nsFormControlHelper::SaveContentState(nsIFrame* aFrame, + nsIPresContext* aPresContext, + nsIPresState** aState) +{ + nsCOMPtr controlContent; + aFrame->GetContent(getter_AddRefs(controlContent)); + + nsCOMPtr control = do_QueryInterface(controlContent); + if (control) { + control->SaveState(aPresContext, aState); + return NS_OK; + } + + return NS_ERROR_FAILURE; +} + +nsresult +nsFormControlHelper::RestoreContentState(nsIFrame* aFrame, + nsIPresContext* aPresContext, + nsIPresState* aState) +{ + nsCOMPtr controlContent; + aFrame->GetContent(getter_AddRefs(controlContent)); + + nsCOMPtr control = do_QueryInterface(controlContent); + if (control) { + control->RestoreState(aPresContext, aState); + return NS_OK; + } + + NS_NOTREACHED("no content"); + return NS_ERROR_FAILURE; +} diff --git a/mozilla/layout/html/forms/src/nsFormControlHelper.h b/mozilla/layout/html/forms/src/nsFormControlHelper.h index cfe795743fc..f5f8bec6a40 100644 --- a/mozilla/layout/html/forms/src/nsFormControlHelper.h +++ b/mozilla/layout/html/forms/src/nsFormControlHelper.h @@ -160,6 +160,12 @@ public: static nsresult GetName(nsIContent* aContent, nsAString* aResult); static nsresult GetInputElementValue(nsIContent* aContent, nsString* aText, PRBool aInitialValue); static nsresult Reset(nsIFrame* aFrame, nsIPresContext* aPresContext); + static nsresult SaveContentState(nsIFrame* aFrame, + nsIPresContext* aPresContext, + nsIPresState** aState); + static nsresult RestoreContentState(nsIFrame* aFrame, + nsIPresContext* aPresContext, + nsIPresState* aState); /** * Utility to convert a string to a PRBool diff --git a/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp index 0945f49b119..562c2b824bc 100644 --- a/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp @@ -466,6 +466,8 @@ nsGfxButtonControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) if (aIID.Equals(NS_GET_IID(nsIAnonymousContentCreator))) { *aInstancePtr = NS_STATIC_CAST(nsIAnonymousContentCreator*, this); + } else if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) { + *aInstancePtr = NS_STATIC_CAST(nsIStatefulFrame*, this); } else { return nsHTMLButtonControlFrame::QueryInterface(aIID, aInstancePtr); @@ -649,3 +651,48 @@ nsGfxButtonControlFrame::HandleEvent(nsIPresContext* aPresContext, return NS_OK; } + +//---------------------------------------------------------------------- +// nsIStatefulFrame +//---------------------------------------------------------------------- +NS_IMETHODIMP +nsGfxButtonControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState) +{ + NS_ENSURE_ARG_POINTER(aState); + + // Get the value string + nsAutoString stateString; + nsresult res = GetProperty(nsHTMLAtoms::value, stateString); + NS_ENSURE_SUCCESS(res, res); + + // Compare to default value, and only save if needed (Bug 62713) + NS_ENSURE_TRUE(mContent->IsContentOfType(nsIContent::eHTML_FORM_CONTROL), + NS_ERROR_UNEXPECTED); + nsAutoString defaultStateString; + if (!mDefaultValueWasChanged) { + mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::value, defaultStateString); + } + + if (mDefaultValueWasChanged || !stateString.Equals(defaultStateString)) { + + // Construct a pres state and store value in it. + res = NS_NewPresState(aState); + NS_ENSURE_SUCCESS(res, res); + res = (*aState)->SetStateProperty(NS_LITERAL_STRING("value"), stateString); + } + + return res; +} + +NS_IMETHODIMP +nsGfxButtonControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState) +{ + NS_ENSURE_ARG_POINTER(aState); + + // Set the value to the stored state. + nsAutoString stateString; + nsresult res = aState->GetStateProperty(NS_LITERAL_STRING("value"), stateString); + NS_ENSURE_SUCCESS(res, res); + + return SetProperty(aPresContext, nsHTMLAtoms::value, stateString); +} diff --git a/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.h b/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.h index 2f0b32bf4bd..cf88e5c95bc 100644 --- a/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.h +++ b/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.h @@ -43,6 +43,7 @@ #include "nsCOMPtr.h" #include "nsIAnonymousContentCreator.h" #include "nsITextContent.h" +#include "nsIStatefulFrame.h" #ifdef ACCESSIBILITY class nsIAccessible; @@ -56,7 +57,8 @@ class nsIAccessible; class nsIPresState; class nsGfxButtonControlFrame : public nsHTMLButtonControlFrame, - public nsIAnonymousContentCreator + public nsIAnonymousContentCreator, + public nsIStatefulFrame { public: nsGfxButtonControlFrame(); @@ -115,6 +117,10 @@ protected: virtual PRBool IsSubmit(PRInt32 type); virtual PRBool IsBrowse(PRInt32 type); // Browse button of file input + //nsIStatefulFrame + NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState); + NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState); + private: NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; } NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; } diff --git a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp index 86a36c4a4ba..a0de56439aa 100644 --- a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp @@ -96,7 +96,10 @@ nsGfxCheckboxControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr NS_ASSERTION(aInstancePtr, "QueryInterface requires a non-NULL destination!"); if ( !aInstancePtr ) return NS_ERROR_NULL_POINTER; - + if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) { + *aInstancePtr = (void*)(nsIStatefulFrame*) this; + return NS_OK; + } if (aIID.Equals(NS_GET_IID(nsICheckboxControlFrame))) { *aInstancePtr = (void*) ((nsICheckboxControlFrame*) this); return NS_OK; @@ -272,6 +275,21 @@ nsGfxCheckboxControlFrame::GetCheckboxState ( ) return retval; } +//---------------------------------------------------------------------- +// nsIStatefulFrame +//---------------------------------------------------------------------- +NS_IMETHODIMP nsGfxCheckboxControlFrame::SaveState(nsIPresContext* aPresContext, + nsIPresState** aState) +{ + return nsFormControlHelper::SaveContentState(this, aPresContext, aState); +} + +NS_IMETHODIMP nsGfxCheckboxControlFrame::RestoreState(nsIPresContext* aPresContext, + nsIPresState* aState) +{ + return nsFormControlHelper::RestoreContentState(this, aPresContext, aState); +} + //------------------------------------------------------------ // Extra Debug Methods //------------------------------------------------------------ diff --git a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.h b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.h index 80e8bd7a67e..16549d7ddd0 100644 --- a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.h +++ b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.h @@ -38,6 +38,7 @@ #define nsGfxCheckboxControlFrame_h___ #include "nsFormControlFrame.h" +#include "nsIStatefulFrame.h" #include "nsICheckboxControlFrame.h" #ifdef ACCESSIBILITY @@ -49,6 +50,7 @@ class nsIAccessible; #define NS_GFX_CHECKBOX_CONTROL_FRAME_LAST_CONTEXT_INDEX 0 class nsGfxCheckboxControlFrame : public nsFormControlFrame, + public nsIStatefulFrame, public nsICheckboxControlFrame//, //public nsIAccessible { @@ -88,7 +90,11 @@ public: // nsIFormControlFrame NS_IMETHOD OnContentReset(); + // nsIStatefulFrame NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); + NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState); + NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState); + #ifdef DEBUG_rodsXXX NS_IMETHOD Reflow(nsIPresContext* aCX, diff --git a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp index 89f0ae2c598..5e0f9b7d33e 100644 --- a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp @@ -94,6 +94,10 @@ nsGfxRadioControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) *aInstancePtr = (void*) ((nsIRadioControlFrame*) this); return NS_OK; } + if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) { + *aInstancePtr = (void*) ((nsIStatefulFrame*) this); + return NS_OK; + } return nsFormControlFrame::QueryInterface(aIID, aInstancePtr); } @@ -253,6 +257,25 @@ nsGfxRadioControlFrame::OnChecked(nsIPresContext* aPresContext, return NS_OK; } +//---------------------------------------------------------------------- +// nsIStatefulFrame +//---------------------------------------------------------------------- +NS_IMETHODIMP +nsGfxRadioControlFrame::SaveState(nsIPresContext* aPresContext, + nsIPresState** aState) +{ + return nsFormControlHelper::SaveContentState(this, aPresContext, aState); +} + + + +//---------------------------------------------------------------------- +NS_IMETHODIMP +nsGfxRadioControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState) +{ + return nsFormControlHelper::RestoreContentState(this, aPresContext, aState); +} + //---------------------------------------------------------------------- // Extra Debug Helper Methods diff --git a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.h b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.h index b04f5debf6d..372fbc5d6a6 100644 --- a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.h +++ b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.h @@ -39,6 +39,7 @@ #define nsGfxRadioControlFrame_h___ #include "nsFormControlFrame.h" +#include "nsIStatefulFrame.h" #include "nsIRadioControlFrame.h" #ifdef ACCESSIBILITY @@ -51,6 +52,7 @@ class nsIAccessible; #define NS_GFX_RADIO_CONTROL_FRAME_LAST_CONTEXT_INDEX 0 class nsGfxRadioControlFrame : public nsFormControlFrame, + public nsIStatefulFrame, public nsIRadioControlFrame { @@ -95,6 +97,10 @@ public: // nsIFormControlFrame NS_IMETHOD OnContentReset(); + //nsIStatefulFrame + NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState); + NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState); + ///XXX: End o the temporary methods #ifdef DEBUG_rodsXXX NS_IMETHOD Reflow(nsIPresContext* aCX, diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp index 8ea4eeca24f..5de5ca0c7fb 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp @@ -1329,6 +1329,10 @@ nsGfxTextControlFrame2::QueryInterface(const nsIID& aIID, void** aInstancePtr) *aInstancePtr = (void*)(nsIGfxTextControlFrame2*) this; return NS_OK; } + if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) { + *aInstancePtr = (void*)(nsIStatefulFrame*) this; + return NS_OK; + } if (aIID.Equals(NS_GET_IID(nsIScrollableViewProvider))) { *aInstancePtr = (void*)(nsIScrollableViewProvider*) this; return NS_OK; @@ -3401,6 +3405,21 @@ nsGfxTextControlFrame2::GetWidthInCharacters() const return DEFAULT_COLUMN_WIDTH; } +//---------------------------------------------------------------------- +// nsIStatefulFrame +//---------------------------------------------------------------------- +NS_IMETHODIMP +nsGfxTextControlFrame2::SaveState(nsIPresContext* aPresContext, nsIPresState** aState) +{ + return nsFormControlHelper::SaveContentState(this, aPresContext, aState); +} + +NS_IMETHODIMP +nsGfxTextControlFrame2::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState) +{ + return nsFormControlHelper::RestoreContentState(this, aPresContext, aState); +} + NS_IMETHODIMP nsGfxTextControlFrame2::GetScrollableView(nsIScrollableView** aView) { diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h index 22d50822390..57ab76c135b 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h @@ -43,6 +43,7 @@ #include "nsIFormControlFrame.h" #include "nsIDOMMouseListener.h" #include "nsIAnonymousContentCreator.h" +#include "nsIStatefulFrame.h" #include "nsIEditor.h" #include "nsIGfxTextControlFrame.h" #include "nsFormControlHelper.h"//for the inputdimensions @@ -69,6 +70,7 @@ class nsIAccessible; class nsGfxTextControlFrame2 : public nsStackFrame, public nsIAnonymousContentCreator, public nsIGfxTextControlFrame2, + public nsIStatefulFrame, public nsIScrollableViewProvider { @@ -229,6 +231,10 @@ protected: PRInt32 GetWidthInCharacters() const; + //nsIStatefulFrame + NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState); + NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState); + // nsIScrollableViewProvider NS_IMETHOD GetScrollableView(nsIScrollableView** aView); diff --git a/mozilla/layout/html/forms/src/nsListControlFrame.cpp b/mozilla/layout/html/forms/src/nsListControlFrame.cpp index 0dcff1613f2..96e0f9d82c4 100644 --- a/mozilla/layout/html/forms/src/nsListControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsListControlFrame.cpp @@ -553,6 +553,10 @@ nsListControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) *aInstancePtr = (void*)(nsIDOMKeyListener*) this; return NS_OK; } + if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) { + *aInstancePtr = (void*)(nsIStatefulFrame*) this; + return NS_OK; + } return nsScrollFrame::QueryInterface(aIID, aInstancePtr); } @@ -1449,7 +1453,7 @@ nsListControlFrame::SetInitialChildList(nsIPresContext* aPresContext, // First check to see if all the content has been added nsCOMPtr element(do_QueryInterface(mContent)); if (element) { - element->IsDoneAddingChildren(&mIsAllContentHere); + element->IsDoneAddingContent(&mIsAllContentHere); if (!mIsAllContentHere) { mIsAllFramesHere = PR_FALSE; mHasBeenInitialized = PR_FALSE; @@ -1965,7 +1969,7 @@ PRBool nsListControlFrame::CheckIfAllFramesHere() //------------------------------------------------------------------- NS_IMETHODIMP -nsListControlFrame::DoneAddingChildren(PRBool aIsDone) +nsListControlFrame::DoneAddingContent(PRBool aIsDone) { mIsAllContentHere = aIsDone; if (mIsAllContentHere) { @@ -1999,7 +2003,7 @@ nsListControlFrame::AddOption(nsIPresContext* aPresContext, PRInt32 aIndex) if (!mIsAllContentHere) { nsCOMPtr element(do_QueryInterface(mContent)); if (element) { - element->IsDoneAddingChildren(&mIsAllContentHere); + element->IsDoneAddingContent(&mIsAllContentHere); if (!mIsAllContentHere) { mIsAllFramesHere = PR_FALSE; mHasBeenInitialized = PR_FALSE; @@ -2771,8 +2775,15 @@ nsListControlFrame::MouseDown(nsIDOMEvent* aMouseEvent) if (NS_SUCCEEDED(mPresContext->GetEventStateManager(getter_AddRefs(stateManager)))) { nsIFrame * frame; stateManager->GetEventTarget(&frame); - if (!IsClickingInCombobox(aMouseEvent)) { - return NS_OK; + nsCOMPtr listFrame(do_QueryInterface(frame)); + if (listFrame) { + if (!IsClickingInCombobox(aMouseEvent)) { + return NS_OK; + } + } else { + if (!IsClickingInCombobox(aMouseEvent)) { + return NS_OK; + } } // This will consume the focus event we get from the clicking on the dropdown //stateManager->ConsumeFocusEvents(PR_TRUE); @@ -3564,3 +3575,21 @@ nsListControlFrame::ItemsHaveBeenRemoved(nsIPresContext * aPresContext) ResetList(aPresContext); } } + + +//-------------------------------------------------------- +// nsIStatefulFrame +//-------------------------------------------------------- +NS_IMETHODIMP +nsListControlFrame::SaveState(nsIPresContext* aPresContext, + nsIPresState** aState) +{ + return nsFormControlHelper::SaveContentState(this, aPresContext, aState); +} + +NS_IMETHODIMP +nsListControlFrame::RestoreState(nsIPresContext* aPresContext, + nsIPresState* aState) +{ + return nsFormControlHelper::RestoreContentState(this, aPresContext, aState); +} diff --git a/mozilla/layout/html/forms/src/nsListControlFrame.h b/mozilla/layout/html/forms/src/nsListControlFrame.h index e6c93e4d526..95784d6707e 100644 --- a/mozilla/layout/html/forms/src/nsListControlFrame.h +++ b/mozilla/layout/html/forms/src/nsListControlFrame.h @@ -58,6 +58,7 @@ #include "nsIPresState.h" #include "nsCWeakReference.h" #include "nsIContent.h" +#include "nsIStatefulFrame.h" class nsIDOMHTMLSelectElement; class nsIDOMHTMLCollection; @@ -67,6 +68,7 @@ class nsIViewManager; class nsIPresContext; class nsVoidArray; class nsIScrollableView; +class nsIStatefulFrame; class nsListControlFrame; class nsSelectUpdateTimer; @@ -281,7 +283,7 @@ public: NS_IMETHOD AddOption(nsIPresContext* aPresContext, PRInt32 index); NS_IMETHOD RemoveOption(nsIPresContext* aPresContext, PRInt32 index); NS_IMETHOD GetOptionSelected(PRInt32 aIndex, PRBool* aValue); - NS_IMETHOD DoneAddingChildren(PRBool aIsDone); + NS_IMETHOD DoneAddingContent(PRBool aIsDone); NS_IMETHOD OnOptionSelected(nsIPresContext* aPresContext, PRInt32 aIndex, PRBool aSelected); @@ -307,6 +309,10 @@ public: NS_IMETHOD KeyUp(nsIDOMEvent* aKeyEvent) { return NS_OK; } NS_IMETHOD KeyPress(nsIDOMEvent* aKeyEvent); + //nsIStatefulFrame + NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState); + NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState); + // Static Methods static nsIDOMHTMLSelectElement* GetSelect(nsIContent * aContent); static nsIDOMHTMLCollection* GetOptions(nsIContent * aContent, nsIDOMHTMLSelectElement* aSelect = nsnull);