From e3111df2a0cc5d0fcc6e19998b725b41719d2743 Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Tue, 13 Jul 2010 23:39:48 -0700 Subject: [PATCH] Bug 578570: Remove nsIOptionElement and nsIRadioControlElement. r=jst --HG-- extra : rebase_source : 9e91a8dd4813109d0bd84fd5e62ce5c28d682976 --- content/html/content/public/Makefile.in | 2 - .../html/content/public/nsIOptionElement.h | 73 ---- .../html/content/src/nsHTMLFormElement.cpp | 16 +- .../html/content/src/nsHTMLInputElement.cpp | 399 ++---------------- content/html/content/src/nsHTMLInputElement.h | 378 +++++++++++++++++ .../html/content/src/nsHTMLOptionElement.cpp | 82 +--- .../html/content/src/nsHTMLOptionElement.h | 112 +++++ .../html/content/src/nsHTMLSelectElement.cpp | 5 +- 8 files changed, 541 insertions(+), 526 deletions(-) delete mode 100644 content/html/content/public/nsIOptionElement.h create mode 100644 content/html/content/src/nsHTMLInputElement.h create mode 100644 content/html/content/src/nsHTMLOptionElement.h diff --git a/content/html/content/public/Makefile.in b/content/html/content/public/Makefile.in index 90c400d6d22..c85423a7686 100644 --- a/content/html/content/public/Makefile.in +++ b/content/html/content/public/Makefile.in @@ -56,8 +56,6 @@ EXPORTS = \ nsIForm.h \ nsIFormProcessor.h \ nsILink.h \ - nsIOptionElement.h \ - nsIRadioControlElement.h \ nsIRadioVisitor.h \ nsIRadioGroupContainer.h \ nsITextControlElement.h \ diff --git a/content/html/content/public/nsIOptionElement.h b/content/html/content/public/nsIOptionElement.h deleted file mode 100644 index 0d9e43436b2..00000000000 --- a/content/html/content/public/nsIOptionElement.h +++ /dev/null @@ -1,73 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ - -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla 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/MPL/ - * - * 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 - * John B. Keiser - * Portions created by the Initial Developer are Copyright (C) 2001 - * 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 MPL, 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 MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsIOptionElement_h___ -#define nsIOptionElement_h___ - -#include "nsISupports.h" - -// IID for the nsIOption interface -#define NS_IOPTIONELEMENT_IID \ -{ 0xd49fe03a, 0x1dd1, 0x11b2, \ - { 0xa0, 0xe0, 0x83, 0x66, 0x76, 0x19, 0xaf, 0x69 } } - -/** - * This interface is used to notify a SELECT when OPTION - * elements are added and removed from its subtree. - * Note that the nsIDOMHTMLSelectElement and nsIContent - * interfaces are the ones to use to access and enumerate - * OPTIONs within a SELECT element. - */ -class nsIOptionElement : public nsISupports { -public: - - NS_DECLARE_STATIC_IID_ACCESSOR(NS_IOPTIONELEMENT_IID) - - /** - * Select the option element from its own point of view. This should only be - * used by SelectElement, really. Everyone else is safe using GetSelected() - * on the DOMHTMLOptionElement, which goes through the ) as an integer. - * @see nsIFormControl.h (specifically NS_FORM_INPUT_*) - */ - PRUint8 mType; - /** - * A bitfield containing our booleans - * @see GET_BOOLBIT / SET_BOOLBIT macros and BF_* field identifiers - */ - PRInt16 mBitField; - /* - * In mInputData, the mState field is used if IsSingleLineTextControl returns - * true and mValue is used otherwise. We have to be careful when handling it - * on a type change. - * - * Accessing the mState member should be done using the GetEditorState function, - * which returns null if the state is not present. - */ - union InputData { - /** - * The current value of the input if it has been changed from the default - */ - char* mValue; - /** - * The state of the text editor associated with the text/password input - */ - nsTextEditorState* mState; - } mInputData; - /** - * The value of the input if it is a file input. This is the list of filenames - * used when uploading a file. It is vital that this is kept separate from - * mValue so that it won't be possible to 'leak' the value from a text-input - * to a file-input. Additionally, the logic for this value is kept as simple - * as possible to avoid accidental errors where the wrong filename is used. - * Therefor the list of filenames is always owned by this member, never by - * the frame. Whenever the frame wants to change the filename it has to call - * SetFileNames to update this member. - */ - nsTArray mFileNames; - - nsRefPtr mFileList; -}; - #ifdef ACCESSIBILITY //Helper method static nsresult FireEventForAccessibility(nsIDOMHTMLInputElement* aTarget, @@ -613,17 +288,16 @@ DOMCI_DATA(HTMLInputElement, nsHTMLInputElement) // QueryInterface implementation for nsHTMLInputElement NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsHTMLInputElement) - NS_HTML_CONTENT_INTERFACE_TABLE10(nsHTMLInputElement, - nsIDOMHTMLInputElement, - nsIDOMNSHTMLInputElement, - nsITextControlElement, - nsIFileControlElement, - nsIRadioControlElement, - nsIPhonetic, - imgIDecoderObserver, - nsIImageLoadingContent, - imgIContainerObserver, - nsIDOMNSEditableElement) + NS_HTML_CONTENT_INTERFACE_TABLE9(nsHTMLInputElement, + nsIDOMHTMLInputElement, + nsIDOMNSHTMLInputElement, + nsITextControlElement, + nsIFileControlElement, + nsIPhonetic, + imgIDecoderObserver, + nsIImageLoadingContent, + imgIContainerObserver, + nsIDOMNSEditableElement) NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLInputElement, nsGenericHTMLFormElement) NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLInputElement) @@ -1341,13 +1015,13 @@ nsHTMLInputElement::GetChecked(PRBool* aChecked) return NS_OK; } -NS_IMETHODIMP +void nsHTMLInputElement::SetCheckedChanged(PRBool aCheckedChanged) { - return DoSetCheckedChanged(aCheckedChanged, PR_TRUE); + DoSetCheckedChanged(aCheckedChanged, PR_TRUE); } -nsresult +void nsHTMLInputElement::DoSetCheckedChanged(PRBool aCheckedChanged, PRBool aNotify) { @@ -1361,22 +1035,19 @@ nsHTMLInputElement::DoSetCheckedChanged(PRBool aCheckedChanged, } else { SetCheckedChangedInternal(aCheckedChanged); } - return NS_OK; } -NS_IMETHODIMP +void nsHTMLInputElement::SetCheckedChangedInternal(PRBool aCheckedChanged) { SET_BOOLBIT(mBitField, BF_CHECKED_CHANGED, aCheckedChanged); - return NS_OK; } -NS_IMETHODIMP -nsHTMLInputElement::GetCheckedChanged(PRBool* aCheckedChanged) +PRBool +nsHTMLInputElement::GetCheckedChanged() { - *aCheckedChanged = GET_BOOLBIT(mBitField, BF_CHECKED_CHANGED); - return NS_OK; + return GET_BOOLBIT(mBitField, BF_CHECKED_CHANGED); } NS_IMETHODIMP @@ -1432,7 +1103,7 @@ nsHTMLInputElement::DoSetChecked(PRBool aChecked, PRBool aNotify) return rv; } -NS_IMETHODIMP +nsresult nsHTMLInputElement::RadioSetChecked(PRBool aNotify) { nsresult rv = NS_OK; @@ -3077,7 +2748,7 @@ nsHTMLInputElement::AllowDrop() * Radio group stuff */ -NS_IMETHODIMP +void nsHTMLInputElement::AddedToRadioGroup(PRBool aNotify) { // Make sure not to notify if we're still being created by the parser @@ -3088,7 +2759,7 @@ nsHTMLInputElement::AddedToRadioGroup(PRBool aNotify) // not in a document, we just need to return. // if (!mForm && !(IsInDoc() && GetParent())) { - return NS_OK; + return; } // @@ -3114,7 +2785,7 @@ nsHTMLInputElement::AddedToRadioGroup(PRBool aNotify) nsCOMPtr visitor; nsresult rv = NS_GetRadioGetCheckedChangedVisitor(&checkedChanged, this, getter_AddRefs(visitor)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) { return; } VisitGroup(visitor, aNotify); SetCheckedChangedInternal(checkedChanged); @@ -3129,11 +2800,9 @@ nsHTMLInputElement::AddedToRadioGroup(PRBool aNotify) container->AddToRadioGroup(name, static_cast(this)); } } - - return NS_OK; } -NS_IMETHODIMP +void nsHTMLInputElement::WillRemoveFromRadioGroup() { // @@ -3141,7 +2810,7 @@ nsHTMLInputElement::WillRemoveFromRadioGroup() // not in a document, we just need to return. // if (!mForm && !(IsInDoc() && GetParent())) { - return NS_OK; + return; } // @@ -3154,7 +2823,7 @@ nsHTMLInputElement::WillRemoveFromRadioGroup() if (!gotName) { if (!GetNameIfExists(name)) { // If the name doesn't exist, nothing is going to happen anyway - return NS_OK; + return; } gotName = PR_TRUE; } @@ -3173,15 +2842,13 @@ nsHTMLInputElement::WillRemoveFromRadioGroup() if (!gotName) { if (!GetNameIfExists(name)) { // If the name doesn't exist, nothing is going to happen anyway - return NS_OK; + return; } gotName = PR_TRUE; } container->RemoveFromRadioGroup(name, static_cast(this)); } - - return NS_OK; } PRBool @@ -3313,8 +2980,9 @@ public: NS_IMETHOD Visit(nsIFormControl* aRadio, PRBool* aStop) { - nsCOMPtr radio(do_QueryInterface(aRadio)); - NS_ASSERTION(radio, "Visit() passed a null button (or non-radio)!"); + nsRefPtr radio = + static_cast(aRadio); + NS_ASSERTION(radio, "Visit() passed a null button!"); radio->SetCheckedChangedInternal(mCheckedChanged); return NS_OK; } @@ -3342,9 +3010,10 @@ public: if (aRadio == mExcludeElement) { return NS_OK; } - nsCOMPtr radio(do_QueryInterface(aRadio)); - NS_ASSERTION(radio, "Visit() passed a null button (or non-radio)!"); - radio->GetCheckedChanged(mCheckedChanged); + nsRefPtr radio = + static_cast(aRadio); + NS_ASSERTION(radio, "Visit() passed a null button!"); + *mCheckedChanged = radio->GetCheckedChanged(); *aStop = PR_TRUE; return NS_OK; } diff --git a/content/html/content/src/nsHTMLInputElement.h b/content/html/content/src/nsHTMLInputElement.h new file mode 100644 index 00000000000..4d4455c7020 --- /dev/null +++ b/content/html/content/src/nsHTMLInputElement.h @@ -0,0 +1,378 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 Communicator client 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): + * Pierre Phaneuf + * + * Alternatively, the contents of this file may be used under the terms of + * either of 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 MPL, 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 MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsHTMLInputElement_h__ +#define nsHTMLInputElement_h__ + +#include "nsGenericHTMLElement.h" +#include "nsImageLoadingContent.h" +#include "nsIDOMHTMLInputElement.h" +#include "nsIDOMNSHTMLInputElement.h" +#include "nsITextControlElement.h" +#include "nsIPhonetic.h" +#include "nsIDOMNSEditableElement.h" +#include "nsIFileControlElement.h" + +#include "nsTextEditorState.h" +#include "nsCOMPtr.h" + +// +// Accessors for mBitField +// +#define BF_DISABLED_CHANGED 0 +#define BF_HANDLING_CLICK 1 +#define BF_VALUE_CHANGED 2 +#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 BF_IN_INTERNAL_ACTIVATE 8 +#define BF_CHECKED_IS_TOGGLED 9 +#define BF_INDETERMINATE 10 +#define BF_INHIBIT_RESTORATION 11 + +#define GET_BOOLBIT(bitfield, field) (((bitfield) & (0x01 << (field))) \ + ? PR_TRUE : PR_FALSE) +#define SET_BOOLBIT(bitfield, field, b) ((b) \ + ? ((bitfield) |= (0x01 << (field))) \ + : ((bitfield) &= ~(0x01 << (field)))) + +class nsDOMFileList; + +class nsHTMLInputElement : public nsGenericHTMLFormElement, + public nsImageLoadingContent, + public nsIDOMHTMLInputElement, + public nsIDOMNSHTMLInputElement, + public nsITextControlElement, + public nsIPhonetic, + public nsIDOMNSEditableElement, + public nsIFileControlElement +{ +public: + nsHTMLInputElement(nsINodeInfo *aNodeInfo, PRUint32 aFromParser); + virtual ~nsHTMLInputElement(); + + // nsISupports + NS_DECL_ISUPPORTS_INHERITED + + // nsIDOMNode + NS_FORWARD_NSIDOMNODE(nsGenericHTMLFormElement::) + + // nsIDOMElement + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFormElement::) + + // nsIDOMHTMLElement + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFormElement::) + + // nsIDOMHTMLInputElement + NS_DECL_NSIDOMHTMLINPUTELEMENT + + // nsIDOMNSHTMLInputElement + NS_DECL_NSIDOMNSHTMLINPUTELEMENT + + // nsIPhonetic + NS_DECL_NSIPHONETIC + + // nsIDOMNSEditableElement + NS_IMETHOD GetEditor(nsIEditor** aEditor) + { + return nsGenericHTMLElement::GetEditor(aEditor); + } + NS_IMETHOD SetUserInput(const nsAString& aInput); + + // Overriden nsIFormControl methods + NS_IMETHOD_(PRUint32) GetType() const { return mType; } + NS_IMETHOD Reset(); + NS_IMETHOD SubmitNamesValues(nsFormSubmission* aFormSubmission, + nsIContent* aSubmitElement); + NS_IMETHOD SaveState(); + virtual PRBool RestoreState(nsPresState* aState); + virtual PRBool AllowDrop(); + + // nsIContent + virtual PRBool IsHTMLFocusable(PRBool aWithMouse, PRBool *aIsFocusable, PRInt32 *aTabIndex); + + virtual PRBool ParseAttribute(PRInt32 aNamespaceID, + nsIAtom* aAttribute, + const nsAString& aValue, + nsAttrValue& aResult); + virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute, + PRInt32 aModType) const; + NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const; + virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const; + + virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor); + virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor); + + virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent, + nsIContent* aBindingParent, + PRBool aCompileEventHandlers); + virtual void UnbindFromTree(PRBool aDeep = PR_TRUE, + PRBool aNullParent = PR_TRUE); + + virtual void DoneCreatingElement(); + + virtual PRInt32 IntrinsicState() const; + + // nsITextControlElement + NS_IMETHOD SetValueChanged(PRBool aValueChanged); + NS_IMETHOD_(PRBool) IsSingleLineTextControl() const; + NS_IMETHOD_(PRBool) IsTextArea() const; + NS_IMETHOD_(PRBool) IsPlainTextControl() const; + NS_IMETHOD_(PRBool) IsPasswordTextControl() const; + NS_IMETHOD_(PRInt32) GetCols(); + NS_IMETHOD_(PRInt32) GetWrapCols(); + NS_IMETHOD_(PRInt32) GetRows(); + NS_IMETHOD_(void) GetDefaultValueFromContent(nsAString& aValue); + NS_IMETHOD_(PRBool) ValueChanged() const; + NS_IMETHOD_(void) GetTextEditorValue(nsAString& aValue, PRBool aIgnoreWrap) const; + NS_IMETHOD_(void) SetTextEditorValue(const nsAString& aValue, PRBool aUserInput); + NS_IMETHOD_(nsIEditor*) GetTextEditor(); + NS_IMETHOD_(nsISelectionController*) GetSelectionController(); + NS_IMETHOD_(nsFrameSelection*) GetConstFrameSelection(); + NS_IMETHOD BindToFrame(nsTextControlFrame* aFrame); + NS_IMETHOD_(void) UnbindFromFrame(nsTextControlFrame* aFrame); + NS_IMETHOD CreateEditor(); + NS_IMETHOD_(nsIContent*) GetRootEditorNode(); + NS_IMETHOD_(nsIContent*) GetPlaceholderNode(); + NS_IMETHOD_(void) UpdatePlaceholderText(PRBool aNotify); + NS_IMETHOD_(void) SetPlaceholderClass(PRBool aVisible, PRBool aNotify); + NS_IMETHOD_(void) InitializeKeyboardEventListeners(); + + // nsIFileControlElement + virtual void GetDisplayFileName(nsAString& aFileName); + virtual void GetFileArray(nsCOMArray &aFile); + virtual void SetFileNames(const nsTArray& aFileNames); + + void SetCheckedChangedInternal(PRBool aCheckedChanged); + PRBool GetCheckedChanged(); + void AddedToRadioGroup(PRBool aNotify = PR_TRUE); + void WillRemoveFromRadioGroup(); + /** + * Get the radio group container for this button (form or document) + * @return the radio group container (or null if no form or document) + */ + virtual already_AddRefed GetRadioGroupContainer(); + + virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; + + virtual void UpdateEditableState() + { + return UpdateEditableFormControlState(); + } + + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLInputElement, + nsGenericHTMLFormElement) + + void MaybeLoadImage(); +protected: + // Pull IsSingleLineTextControl into our scope, otherwise it'd be hidden + // by the nsITextControlElement version. + using nsGenericHTMLFormElement::IsSingleLineTextControl; + + // Helper method + nsresult SetValueInternal(const nsAString& aValue, + PRBool aUserInput); + + void ClearFileNames() { + nsTArray fileNames; + SetFileNames(fileNames); + } + + void SetSingleFileName(const nsAString& aFileName) { + nsAutoTArray fileNames; + fileNames.AppendElement(aFileName); + SetFileNames(fileNames); + } + + nsresult SetIndeterminateInternal(PRBool aValue, + PRBool aShouldInvalidate); + + nsresult GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd); + + /** + * Get the name if it exists and return whether it did exist + * @param aName the name returned [OUT] + * @param true if the name is empty, false otherwise + */ + PRBool GetNameIfExists(nsAString& aName) { + GetAttr(kNameSpaceID_None, nsGkAtoms::name, aName); + return !aName.IsEmpty(); + } + + /** + * Called when an attribute is about to be changed + */ + virtual nsresult BeforeSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, + const nsAString* aValue, PRBool aNotify); + /** + * Called when an attribute has just been changed + */ + virtual nsresult AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, + const nsAString* aValue, PRBool aNotify); + + /** + * Dispatch a select event. Returns true if the event was not cancelled. + */ + PRBool DispatchSelectEvent(nsPresContext* aPresContext); + + void SelectAll(nsPresContext* aPresContext); + PRBool IsImage() const + { + return AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, + nsGkAtoms::image, eIgnoreCase); + } + + virtual PRBool AcceptAutofocus() const + { + return PR_TRUE; + } + + /** + * Fire the onChange event + */ + void FireOnChange(); + + /** + * Visit a the group of radio buttons this radio belongs to + * @param aVisitor the visitor to visit with + */ + nsresult VisitGroup(nsIRadioVisitor* aVisitor, PRBool aFlushContent); + + /** + * Do all the work that |SetChecked| does (radio button handling, etc.), but + * take an |aNotify| parameter. + */ + nsresult DoSetChecked(PRBool aValue, PRBool aNotify = PR_TRUE); + + /** + * Do all the work that |SetCheckedChanged| does (radio button handling, + * etc.), but take an |aNotify| parameter that lets it avoid flushing content + * when it can. + */ + void DoSetCheckedChanged(PRBool aCheckedChanged, PRBool aNotify); + + /** + * Actually set checked and notify the frame of the change. + * @param aValue the value of checked to set + */ + nsresult SetCheckedInternal(PRBool aValue, PRBool aNotify); + + /** + * Syntax sugar to make it easier to check for checked + */ + PRBool GetChecked() const + { + return GET_BOOLBIT(mBitField, BF_CHECKED); + } + + nsresult RadioSetChecked(PRBool aNotify); + void SetCheckedChanged(PRBool aCheckedChanged); + + /** + * MaybeSubmitForm looks for a submit input or a single text control + * and submits the form if either is present. + */ + nsresult MaybeSubmitForm(nsPresContext* aPresContext); + + /** + * Update mFileList with the currently selected file. + */ + nsresult UpdateFileList(); + + /** + * Determine whether the editor needs to be initialized explicitly for + * a particular event. + */ + PRBool NeedToInitializeEditorForEvent(nsEventChainPreVisitor& aVisitor) const; + + void FreeData(); + nsTextEditorState *GetEditorState() const; + + /** + * Manages the internal data storage across type changes. + */ + void HandleTypeChange(PRUint8 aNewType); + + nsCOMPtr mControllers; + + /** + * The type of this input () as an integer. + * @see nsIFormControl.h (specifically NS_FORM_INPUT_*) + */ + PRUint8 mType; + /** + * A bitfield containing our booleans + * @see GET_BOOLBIT / SET_BOOLBIT macros and BF_* field identifiers + */ + PRInt16 mBitField; + /* + * In mInputData, the mState field is used if IsSingleLineTextControl returns + * true and mValue is used otherwise. We have to be careful when handling it + * on a type change. + * + * Accessing the mState member should be done using the GetEditorState function, + * which returns null if the state is not present. + */ + union InputData { + /** + * The current value of the input if it has been changed from the default + */ + char* mValue; + /** + * The state of the text editor associated with the text/password input + */ + nsTextEditorState* mState; + } mInputData; + /** + * The value of the input if it is a file input. This is the list of filenames + * used when uploading a file. It is vital that this is kept separate from + * mValue so that it won't be possible to 'leak' the value from a text-input + * to a file-input. Additionally, the logic for this value is kept as simple + * as possible to avoid accidental errors where the wrong filename is used. + * Therefor the list of filenames is always owned by this member, never by + * the frame. Whenever the frame wants to change the filename it has to call + * SetFileNames to update this member. + */ + nsTArray mFileNames; + + nsRefPtr mFileList; +}; + +#endif diff --git a/content/html/content/src/nsHTMLOptionElement.cpp b/content/html/content/src/nsHTMLOptionElement.cpp index cec74f3a252..c7aa762db95 100644 --- a/content/html/content/src/nsHTMLOptionElement.cpp +++ b/content/html/content/src/nsHTMLOptionElement.cpp @@ -37,13 +37,12 @@ * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ -#include "nsIDOMHTMLOptionElement.h" + #include "nsIDOMNSHTMLOptionElement.h" -#include "nsIOptionElement.h" +#include "nsHTMLOptionElement.h" #include "nsIDOMHTMLOptGroupElement.h" #include "nsIDOMHTMLFormElement.h" #include "nsIDOMEventTarget.h" -#include "nsGenericHTMLElement.h" #include "nsGkAtoms.h" #include "nsStyleConsts.h" #include "nsIFormControl.h" @@ -52,7 +51,6 @@ #include "nsIDOMNode.h" #include "nsGenericElement.h" #include "nsIDOMHTMLCollection.h" -#include "nsIJSNativeInitializer.h" #include "nsISelectElement.h" #include "nsISelectControlFrame.h" @@ -72,70 +70,6 @@ /** * Implementation of <option> */ -class nsHTMLOptionElement : public nsGenericHTMLElement, - public nsIDOMHTMLOptionElement, - public nsIDOMNSHTMLOptionElement, - public nsIJSNativeInitializer, - public nsIOptionElement -{ -public: - nsHTMLOptionElement(nsINodeInfo *aNodeInfo); - virtual ~nsHTMLOptionElement(); - - // nsISupports - NS_DECL_ISUPPORTS_INHERITED - - // nsIDOMNode - NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::) - - // nsIDOMElement - NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::) - - // nsIDOMHTMLElement - NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::) - - // nsIDOMHTMLOptionElement - NS_DECL_NSIDOMHTMLOPTIONELEMENT - - // nsIDOMNSHTMLOptionElement - NS_IMETHOD SetText(const nsAString & aText); - - // nsIJSNativeInitializer - NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aContext, - JSObject *aObj, PRUint32 argc, jsval *argv); - - virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute, - PRInt32 aModType) const; - - virtual nsresult BeforeSetAttr(PRInt32 aNamespaceID, nsIAtom* aName, - const nsAString* aValue, PRBool aNotify); - - // nsIOptionElement - NS_IMETHOD SetSelectedInternal(PRBool aValue, PRBool aNotify); - - // nsIContent - virtual PRInt32 IntrinsicState() const; - - virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; - - nsresult CopyInnerTo(nsGenericElement* aDest) const; - -protected: - /** - * Get the select content element that contains this option, this - * intentionally does not return nsresult, all we care about is if - * there's a select associated with this option or not. - * @param aSelectElement the select element (out param) - */ - nsIContent* GetSelect(); - - PRPackedBool mSelectedChanged; - PRPackedBool mIsSelected; - - // True only while we're under the SetOptionsSelectedByIndex call when our - // "selected" attribute is changing and mSelectedChanged is false. - PRPackedBool mIsInSetDefaultSelected; -}; nsGenericHTMLElement* NS_NewHTMLOptionElement(nsINodeInfo *aNodeInfo, PRUint32 aFromParser) @@ -182,11 +116,10 @@ DOMCI_DATA(HTMLOptionElement, nsHTMLOptionElement) // QueryInterface implementation for nsHTMLOptionElement NS_INTERFACE_TABLE_HEAD(nsHTMLOptionElement) - NS_HTML_CONTENT_INTERFACE_TABLE4(nsHTMLOptionElement, + NS_HTML_CONTENT_INTERFACE_TABLE3(nsHTMLOptionElement, nsIDOMHTMLOptionElement, nsIDOMNSHTMLOptionElement, - nsIJSNativeInitializer, - nsIOptionElement) + nsIJSNativeInitializer) NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLOptionElement, nsGenericHTMLElement) NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLOptionElement) @@ -210,7 +143,7 @@ nsHTMLOptionElement::GetForm(nsIDOMHTMLFormElement** aForm) return NS_OK; } -NS_IMETHODIMP +void nsHTMLOptionElement::SetSelectedInternal(PRBool aValue, PRBool aNotify) { mSelectedChanged = PR_TRUE; @@ -225,8 +158,6 @@ nsHTMLOptionElement::SetSelectedInternal(PRBool aValue, PRBool aNotify) document->ContentStatesChanged(this, nsnull, NS_EVENT_STATE_CHECKED); } } - - return NS_OK; } NS_IMETHODIMP @@ -277,7 +208,8 @@ nsHTMLOptionElement::SetSelected(PRBool aValue) PR_FALSE, PR_TRUE, PR_TRUE, nsnull); } else { - return SetSelectedInternal(aValue, PR_TRUE); + SetSelectedInternal(aValue, PR_TRUE); + return NS_OK; } return NS_OK; diff --git a/content/html/content/src/nsHTMLOptionElement.h b/content/html/content/src/nsHTMLOptionElement.h new file mode 100644 index 00000000000..3df6d48ddbc --- /dev/null +++ b/content/html/content/src/nsHTMLOptionElement.h @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=2 sw=2 et tw=78: */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 Communicator client 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): + * Pierre Phaneuf + * Mats Palmgren + * + * Alternatively, the contents of this file may be used under the terms of + * either of 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 MPL, 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 MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsHTMLOptionElement_h__ +#define nsHTMLOptionElement_h__ + +#include "nsGenericHTMLElement.h" +#include "nsIDOMHTMLOptionElement.h" +#include "nsIDOMNSHTMLOptionElement.h" +#include "nsIJSNativeInitializer.h" + +class nsHTMLOptionElement : public nsGenericHTMLElement, + public nsIDOMHTMLOptionElement, + public nsIDOMNSHTMLOptionElement, + public nsIJSNativeInitializer +{ +public: + nsHTMLOptionElement(nsINodeInfo *aNodeInfo); + virtual ~nsHTMLOptionElement(); + + // nsISupports + NS_DECL_ISUPPORTS_INHERITED + + // nsIDOMNode + NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::) + + // nsIDOMElement + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::) + + // nsIDOMHTMLElement + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::) + + // nsIDOMHTMLOptionElement + NS_DECL_NSIDOMHTMLOPTIONELEMENT + + // nsIDOMNSHTMLOptionElement + NS_IMETHOD SetText(const nsAString & aText); + + // nsIJSNativeInitializer + NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aContext, + JSObject *aObj, PRUint32 argc, jsval *argv); + + virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute, + PRInt32 aModType) const; + + virtual nsresult BeforeSetAttr(PRInt32 aNamespaceID, nsIAtom* aName, + const nsAString* aValue, PRBool aNotify); + + void SetSelectedInternal(PRBool aValue, PRBool aNotify); + + // nsIContent + virtual PRInt32 IntrinsicState() const; + + virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; + + nsresult CopyInnerTo(nsGenericElement* aDest) const; + +protected: + /** + * Get the select content element that contains this option, this + * intentionally does not return nsresult, all we care about is if + * there's a select associated with this option or not. + * @param aSelectElement the select element (out param) + */ + nsIContent* GetSelect(); + + PRPackedBool mSelectedChanged; + PRPackedBool mIsSelected; + + // True only while we're under the SetOptionsSelectedByIndex call when our + // "selected" attribute is changing and mSelectedChanged is false. + PRPackedBool mIsInSetDefaultSelected; +}; + +#endif diff --git a/content/html/content/src/nsHTMLSelectElement.cpp b/content/html/content/src/nsHTMLSelectElement.cpp index 6bca3b5c54f..7f4565f8280 100644 --- a/content/html/content/src/nsHTMLSelectElement.cpp +++ b/content/html/content/src/nsHTMLSelectElement.cpp @@ -50,7 +50,7 @@ #include "nsContentCreatorFunctions.h" #include "nsIDOMHTMLOptGroupElement.h" -#include "nsIOptionElement.h" +#include "nsHTMLOptionElement.h" #include "nsIEventStateManager.h" #include "nsGUIEvent.h" #include "nsIPrivateDOMEvent.h" @@ -828,7 +828,8 @@ nsHTMLSelectElement::OnOptionSelected(nsISelectControlFrame* aSelectFrame, nsCOMPtr option; Item(aIndex, getter_AddRefs(option)); if (option) { - nsCOMPtr optionElement(do_QueryInterface(option)); + nsRefPtr optionElement = + static_cast(option.get()); optionElement->SetSelectedInternal(aSelected, aNotify); } }