Backout 249ee5a4b51d, f3003a80bf28 and 1b4359586ce5 to fix leak.

--HG--
extra : rebase_source : effdeb6ac33a5a065689ca5c3f8f6da249eb6375
This commit is contained in:
Peter Van der Beken 2010-07-14 15:45:11 +02:00
parent 7846424f94
commit ba965ac95d
18 changed files with 312 additions and 424 deletions

View File

@ -2188,7 +2188,9 @@ nsAccessible::GetRelationByType(PRUint32 aRelationType,
// HTML form controls implements nsIFormControl interface.
nsCOMPtr<nsIFormControl> control(do_QueryInterface(mContent));
if (control) {
nsCOMPtr<nsIForm> form(do_QueryInterface(control->GetFormElement()));
nsCOMPtr<nsIDOMHTMLFormElement> htmlform;
control->GetForm(getter_AddRefs(htmlform));
nsCOMPtr<nsIForm> form(do_QueryInterface(htmlform));
if (form) {
nsCOMPtr<nsIContent> formContent =
do_QueryInterface(form->GetDefaultSubmitElement());

View File

@ -170,11 +170,15 @@ nsFormContentList::nsFormContentList(nsIDOMHTMLFormElement *aForm,
// move elements that belong to mForm into this content list
PRUint32 i, length = 0;
nsCOMPtr<nsIDOMNode> item;
aContentList.GetLength(&length);
for (i = 0; i < length; i++) {
nsIContent *c = aContentList.GetNodeAt(i);
aContentList.Item(i, getter_AddRefs(item));
nsCOMPtr<nsIContent> c(do_QueryInterface(item));
if (c && nsContentUtils::BelongsInForm(aForm, c)) {
AppendElement(c);
}

View File

@ -1914,10 +1914,11 @@ static inline void KeyAppendAtom(nsIAtom* aAtom, nsACString& aKey)
KeyAppendString(nsAtomCString(aAtom), aKey);
}
static inline PRBool IsAutocompleteOff(nsIContent* aElement)
static inline PRBool IsAutocompleteOff(nsIDOMElement* aElement)
{
return aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::autocomplete,
NS_LITERAL_STRING("off"), eIgnoreCase);
nsAutoString autocomplete;
aElement->GetAttribute(NS_LITERAL_STRING("autocomplete"), autocomplete);
return autocomplete.LowerCaseEqualsLiteral("off");
}
/*static*/ nsresult
@ -1946,7 +1947,8 @@ nsContentUtils::GenerateStateKey(nsIContent* aContent,
return NS_OK;
}
if (IsAutocompleteOff(aContent)) {
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(aContent));
if (element && IsAutocompleteOff(element)) {
return NS_OK;
}
@ -1992,8 +1994,10 @@ nsContentUtils::GenerateStateKey(nsIContent* aContent,
// If in a form, add form name / index of form / index in form
PRInt32 index = -1;
Element *formElement = control->GetFormElement();
nsCOMPtr<nsIDOMHTMLFormElement> formElement;
control->GetForm(getter_AddRefs(formElement));
if (formElement) {
if (IsAutocompleteOff(formElement)) {
aKey.Truncate();
return NS_OK;
@ -2002,7 +2006,8 @@ nsContentUtils::GenerateStateKey(nsIContent* aContent,
KeyAppendString(NS_LITERAL_CSTRING("f"), aKey);
// Append the index of the form in the document
index = htmlForms->IndexOf(formElement, PR_FALSE);
nsCOMPtr<nsIContent> formContent(do_QueryInterface(formElement));
index = htmlForms->IndexOf(formContent, PR_FALSE);
if (index <= -1) {
//
// XXX HACK this uses some state that was dumped into the document
@ -2028,7 +2033,7 @@ nsContentUtils::GenerateStateKey(nsIContent* aContent,
// Append the form name
nsAutoString formName;
formElement->GetAttr(kNameSpaceID_None, nsGkAtoms::name, formName);
formElement->GetName(formName);
KeyAppendString(formName, aKey);
} else {

View File

@ -72,10 +72,11 @@ nsDOMAttributeMap::Init()
* Clear map pointer for attributes.
*/
PLDHashOperator
RemoveMapRef(nsAttrHashKey::KeyType aKey, nsRefPtr<nsDOMAttribute>& aData,
void* aUserArg)
RemoveMapRef(nsAttrHashKey::KeyType aKey, nsCOMPtr<nsIDOMNode>& aData, void* aUserArg)
{
aData->SetMap(nsnull);
nsCOMPtr<nsIAttribute> attr(do_QueryInterface(aData));
NS_ASSERTION(attr, "non-nsIAttribute somehow made it into the hashmap?!");
attr->SetMap(nsnull);
return PL_DHASH_REMOVE;
}
@ -100,13 +101,12 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
PLDHashOperator
TraverseMapEntry(nsAttrHashKey::KeyType aKey, nsRefPtr<nsDOMAttribute>& aData,
void* aUserArg)
TraverseMapEntry(nsAttrHashKey::KeyType aKey, nsCOMPtr<nsIDOMNode>& aData, void* aUserArg)
{
nsCycleCollectionTraversalCallback *cb =
static_cast<nsCycleCollectionTraversalCallback*>(aUserArg);
cb->NoteXPCOMChild(static_cast<nsINode*>(aData.get()));
cb->NoteXPCOMChild(aData.get());
return PL_DHASH_NEXT;
}
@ -131,11 +131,12 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMAttributeMap)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMAttributeMap)
PLDHashOperator
SetOwnerDocumentFunc(nsAttrHashKey::KeyType aKey,
nsRefPtr<nsDOMAttribute>& aData,
SetOwnerDocumentFunc(nsAttrHashKey::KeyType aKey, nsCOMPtr<nsIDOMNode>& aData,
void* aUserArg)
{
nsresult rv = aData->SetOwnerDocument(static_cast<nsIDocument*>(aUserArg));
nsCOMPtr<nsIAttribute> attr(do_QueryInterface(aData));
NS_ASSERTION(attr, "non-nsIAttribute somehow made it into the hashmap?!");
nsresult rv = attr->SetOwnerDocument(static_cast<nsIDocument*>(aUserArg));
return NS_FAILED(rv) ? PL_DHASH_STOP : PL_DHASH_NEXT;
}
@ -153,10 +154,13 @@ void
nsDOMAttributeMap::DropAttribute(PRInt32 aNamespaceID, nsIAtom* aLocalName)
{
nsAttrKey attr(aNamespaceID, aLocalName);
nsDOMAttribute *node = mAttributeCache.GetWeak(attr);
nsIDOMNode *node = mAttributeCache.GetWeak(attr);
if (node) {
nsCOMPtr<nsIAttribute> iAttr(do_QueryInterface(node));
NS_ASSERTION(iAttr, "non-nsIAttribute somehow made it into the hashmap?!");
// Break link to map
node->SetMap(nsnull);
iAttr->SetMap(nsnull);
// Remove from cache
mAttributeCache.Remove(attr);
@ -173,8 +177,7 @@ nsDOMAttributeMap::RemoveAttribute(nsINodeInfo* aNodeInfo, nsIDOMNode** aReturn)
nsAttrKey attr(aNodeInfo->NamespaceID(), aNodeInfo->NameAtom());
nsRefPtr<nsDOMAttribute> node;
if (!mAttributeCache.Get(attr, getter_AddRefs(node))) {
if (!mAttributeCache.Get(attr, aReturn)) {
nsAutoString value;
// As we are removing the attribute we need to set the current value in
// the attribute node.
@ -186,28 +189,29 @@ nsDOMAttributeMap::RemoveAttribute(nsINodeInfo* aNodeInfo, nsIDOMNode** aReturn)
newAttr.swap(*aReturn);
}
else {
nsCOMPtr<nsIAttribute> iAttr(do_QueryInterface(*aReturn));
NS_ASSERTION(iAttr, "non-nsIAttribute somehow made it into the hashmap?!");
// Break link to map
node->SetMap(nsnull);
iAttr->SetMap(nsnull);
// Remove from cache
mAttributeCache.Remove(attr);
node.forget(aReturn);
}
return NS_OK;
}
nsDOMAttribute*
nsIDOMNode*
nsDOMAttributeMap::GetAttribute(nsINodeInfo* aNodeInfo)
{
NS_ASSERTION(aNodeInfo, "GetAttribute() called with aNodeInfo == nsnull!");
nsAttrKey attr(aNodeInfo->NamespaceID(), aNodeInfo->NameAtom());
nsDOMAttribute* node = mAttributeCache.GetWeak(attr);
nsIDOMNode* node = mAttributeCache.GetWeak(attr);
if (!node) {
nsRefPtr<nsDOMAttribute> newAttr =
nsCOMPtr<nsIDOMNode> newAttr =
new nsDOMAttribute(this, aNodeInfo, EmptyString());
if (newAttr && mAttributeCache.Put(attr, newAttr)) {
node = newAttr;
@ -217,7 +221,7 @@ nsDOMAttributeMap::GetAttribute(nsINodeInfo* aNodeInfo)
return node;
}
nsDOMAttribute*
nsIDOMNode*
nsDOMAttributeMap::GetNamedItem(const nsAString& aAttrName, nsresult *aResult)
{
*aResult = NS_OK;
@ -226,7 +230,12 @@ nsDOMAttributeMap::GetNamedItem(const nsAString& aAttrName, nsresult *aResult)
nsCOMPtr<nsINodeInfo> ni =
mContent->GetExistingAttrNameFromQName(aAttrName);
if (ni) {
return GetAttribute(ni);
nsIDOMNode* node = GetAttribute(ni);
if (node) {
return node;
}
*aResult = NS_ERROR_OUT_OF_MEMORY;
}
}
@ -273,13 +282,12 @@ nsDOMAttributeMap::SetNamedItemInternal(nsIDOMNode *aNode,
// XXX should check same-origin between mContent and aNode however
// nsContentUtils::CheckSameOrigin can't deal with attributenodes yet
nsCOMPtr<nsIDOMAttr> attribute(do_QueryInterface(aNode));
nsCOMPtr<nsIAttribute> iAttribute(do_QueryInterface(aNode));
if (!iAttribute) {
if (!attribute || !iAttribute) {
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
nsDOMAttribute *attribute = static_cast<nsDOMAttribute*>(iAttribute.get());
// Check that attribute is not owned by somebody else
nsDOMAttributeMap* owner = iAttribute->GetMap();
if (owner) {
@ -381,7 +389,8 @@ nsDOMAttributeMap::RemoveNamedItem(const nsAString& aName,
return NS_ERROR_DOM_NOT_FOUND_ERR;
}
NS_ADDREF(*aReturn = GetAttribute(ni));
rv = GetAttribute(ni, aReturn);
NS_ENSURE_SUCCESS(rv, rv);
// This removes the attribute node from the attribute map.
rv = mContent->UnsetAttr(ni->NamespaceID(), ni->NameAtom(), PR_TRUE);
@ -391,12 +400,12 @@ nsDOMAttributeMap::RemoveNamedItem(const nsAString& aName,
}
nsDOMAttribute*
nsIDOMNode*
nsDOMAttributeMap::GetItemAt(PRUint32 aIndex, nsresult *aResult)
{
*aResult = NS_OK;
nsDOMAttribute* node = nsnull;
nsIDOMNode* node = nsnull;
const nsAttrName* name;
if (mContent && (name = mContent->GetAttrNameAt(aIndex))) {
@ -408,7 +417,7 @@ nsDOMAttributeMap::GetItemAt(PRUint32 aIndex, nsresult *aResult)
if (ni) {
node = GetAttribute(ni);
}
else {
if (!node) {
*aResult = NS_ERROR_OUT_OF_MEMORY;
}
}
@ -484,11 +493,7 @@ nsDOMAttributeMap::GetNamedItemNSInternal(const nsAString& aNamespaceURI,
GetNodeInfo(nameAtom, name->GetPrefix(), nameSpaceID);
NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY);
if (aRemove) {
return RemoveAttribute(ni, aReturn);
}
NS_ADDREF(*aReturn = GetAttribute(ni));
return aRemove ? RemoveAttribute(ni, aReturn) : GetAttribute(ni, aReturn);
}
}

View File

@ -45,7 +45,7 @@
#include "nsIDOMNamedNodeMap.h"
#include "nsString.h"
#include "nsRefPtrHashtable.h"
#include "nsInterfaceHashtable.h"
#include "nsCycleCollectionParticipant.h"
#include "prbit.h"
#include "nsIDOMNode.h"
@ -160,7 +160,7 @@ public:
*/
PRUint32 Count() const;
typedef nsRefPtrHashtable<nsAttrHashKey, nsDOMAttribute> AttrCache;
typedef nsInterfaceHashtable<nsAttrHashKey, nsIDOMNode> AttrCache;
/**
* Enumerates over the attribute nodess in the map and calls aFunc for each
@ -170,8 +170,8 @@ public:
*/
PRUint32 Enumerate(AttrCache::EnumReadFunction aFunc, void *aUserArg) const;
nsDOMAttribute* GetItemAt(PRUint32 aIndex, nsresult *rv);
nsDOMAttribute* GetNamedItem(const nsAString& aAttrName, nsresult *rv);
nsIDOMNode* GetItemAt(PRUint32 aIndex, nsresult *rv);
nsIDOMNode* GetNamedItem(const nsAString& aAttrName, nsresult *rv);
static nsDOMAttributeMap* FromSupports(nsISupports* aSupports)
{
@ -217,7 +217,24 @@ private:
nsIDOMNode** aReturn,
PRBool aRemove = PR_FALSE);
nsDOMAttribute* GetAttribute(nsINodeInfo* aNodeInfo);
/**
* Returns an attribute, either by retrieving it from the cache or by
* creating a new one.
*/
nsresult GetAttribute(nsINodeInfo* aNodeInfo,
nsIDOMNode** aReturn)
{
*aReturn = GetAttribute(aNodeInfo);
if (!*aReturn) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(*aReturn);
return NS_OK;
}
nsIDOMNode* GetAttribute(nsINodeInfo* aNodeInfo);
/**
* Remove an attribute, returns the removed node.

View File

@ -5619,12 +5619,12 @@ nsDocument::SetDocumentURI(const nsAString& aDocumentURI)
static void BlastSubtreeToPieces(nsINode *aNode);
PLDHashOperator
BlastFunc(nsAttrHashKey::KeyType aKey, nsDOMAttribute *aData, void* aUserArg)
BlastFunc(nsAttrHashKey::KeyType aKey, nsIDOMNode *aData, void* aUserArg)
{
nsCOMPtr<nsIAttribute> *attr =
static_cast<nsCOMPtr<nsIAttribute>*>(aUserArg);
*attr = aData;
*attr = do_QueryInterface(aData);
NS_ASSERTION(attr->get(),
"non-nsIAttribute somehow made it into the hashmap?!");

View File

@ -38,13 +38,14 @@
#ifndef nsNodeUtils_h___
#define nsNodeUtils_h___
#include "nsDOMAttributeMap.h"
#include "nsIDOMNode.h"
#include "nsINode.h"
struct CharacterDataChangeInfo;
struct JSContext;
struct JSObject;
class nsIVariant;
class nsIDOMNode;
class nsIDOMUserDataHandler;
template<class E> class nsCOMArray;
class nsCycleCollectionTraversalCallback;
@ -249,6 +250,9 @@ public:
static void UnlinkUserData(nsINode *aNode);
private:
friend PLDHashOperator
AdoptFunc(nsAttrHashKey::KeyType aKey, nsIDOMNode *aData, void* aUserArg);
/**
* Walks aNode, its attributes and, if aDeep is PR_TRUE, its descendant nodes.
* If aClone is PR_TRUE the nodes will be cloned. If aNewNodeInfoManager is

View File

@ -45,12 +45,6 @@ class nsString;
class nsIFormProcessor;
class nsFormSubmission;
namespace mozilla {
namespace dom {
class Element;
} // namespace dom
} // namespace mozilla
enum FormControlsTypes {
NS_FORM_FIELDSET = 1,
NS_FORM_LABEL,
@ -99,8 +93,8 @@ PR_STATIC_ASSERT((PRUint32)eButtonElementTypesMax < (PRUint32)NS_FORM_INPUT_ELEM
PR_STATIC_ASSERT((PRUint32)eInputElementTypesMax < 1<<8);
#define NS_IFORMCONTROL_IID \
{ 0x0dc5083b, 0xb0a8, 0x48c4, \
{ 0xb2, 0xeb, 0xc2, 0x4f, 0xfb, 0x7e, 0xc2, 0x8e } }
{ 0x52dc1f0d, 0x1683, 0x4dd7, \
{ 0xae, 0x0a, 0xc4, 0x76, 0x10, 0x64, 0x2f, 0xa8 } }
/**
* Interface which all form controls (e.g. buttons, checkboxes, text,
@ -115,9 +109,9 @@ public:
/**
* Get the form for this form control.
* @return the form
* @param aForm the form [OUT]
*/
virtual mozilla::dom::Element *GetFormElement() = 0;
NS_IMETHOD GetForm(nsIDOMHTMLFormElement** aForm) = 0;
/**
* Set the form for this form control.

View File

@ -111,9 +111,6 @@
#include "mozAutoDocUpdate.h"
#include "nsHtml5Module.h"
#include "nsITextControlElement.h"
#include "mozilla/dom/Element.h"
using namespace mozilla::dom;
#include "nsThreadUtils.h"
@ -2382,13 +2379,7 @@ nsGenericHTMLFormElement::ClearForm(PRBool aRemoveFromForm,
mForm = nsnull;
}
Element*
nsGenericHTMLFormElement::GetFormElement()
{
return mForm;
}
nsresult
NS_IMETHODIMP
nsGenericHTMLFormElement::GetForm(nsIDOMHTMLFormElement** aForm)
{
NS_ENSURE_ARG_POINTER(aForm);

View File

@ -803,12 +803,10 @@ public:
virtual void SaveSubtreeState();
// nsIFormControl
virtual mozilla::dom::Element* GetFormElement();
NS_IMETHOD GetForm(nsIDOMHTMLFormElement** aForm);
virtual void SetForm(nsIDOMHTMLFormElement* aForm);
virtual void ClearForm(PRBool aRemoveFromForm, PRBool aNotify);
nsresult GetForm(nsIDOMHTMLFormElement** aForm);
NS_IMETHOD SaveState()
{
return NS_OK;

View File

@ -48,7 +48,6 @@
#include "nsPIDOMWindow.h"
#include "nsUnicharUtils.h"
#include "nsThreadUtils.h"
#include "nsInterfaceHashtable.h"
class nsFormControlList;

View File

@ -35,9 +35,10 @@
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsHTMLLegendElement.h"
#include "nsIDOMHTMLLegendElement.h"
#include "nsIDOMHTMLFormElement.h"
#include "nsIDOMEventTarget.h"
#include "nsGenericHTMLElement.h"
#include "nsGkAtoms.h"
#include "nsStyleConsts.h"
#include "nsIForm.h"
@ -48,6 +49,68 @@
#include "nsFocusManager.h"
#include "nsIFrame.h"
class nsHTMLLegendElement : public nsGenericHTMLElement,
public nsIDOMHTMLLegendElement
{
public:
nsHTMLLegendElement(nsINodeInfo *aNodeInfo);
virtual ~nsHTMLLegendElement();
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
// nsIDOMNode
NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
// nsIDOMElement
NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
// nsIDOMHTMLElement
NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
// nsIDOMHTMLLegendElement
NS_DECL_NSIDOMHTMLLEGENDELEMENT
// nsGenericHTMLElement
NS_IMETHODIMP Focus();
virtual void PerformAccesskey(PRBool aKeyCausesActivation,
PRBool aIsTrustedEvent);
// nsIContent
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
nsIContent* aBindingParent,
PRBool aCompileEventHandlers);
virtual void UnbindFromTree(PRBool aDeep = PR_TRUE,
PRBool aNullParent = PR_TRUE);
virtual PRBool ParseAttribute(PRInt32 aNamespaceID,
nsIAtom* aAttribute,
const nsAString& aValue,
nsAttrValue& aResult);
virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
PRInt32 aModType) const;
nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString& aValue, PRBool aNotify)
{
return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
}
virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
nsIAtom* aPrefix, const nsAString& aValue,
PRBool aNotify);
virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
PRBool aNotify);
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
protected:
/**
* Get the fieldset content element that contains this legend.
* Returns null if there is no fieldset containing this legend.
*/
nsIContent* GetFieldSet();
};
NS_IMPL_NS_NEW_HTML_ELEMENT(Legend)
@ -84,9 +147,11 @@ NS_IMPL_ELEMENT_CLONE(nsHTMLLegendElement)
NS_IMETHODIMP
nsHTMLLegendElement::GetForm(nsIDOMHTMLFormElement** aForm)
{
Element *form = GetFormElement();
*aForm = nsnull;
return form ? CallQueryInterface(form, aForm) : NS_OK;
nsCOMPtr<nsIFormControl> fieldsetControl = do_QueryInterface(GetFieldSet());
return fieldsetControl ? fieldsetControl->GetForm(aForm) : NS_OK;
}

View File

@ -1,119 +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 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):
* Mats Palmgren <mats.palmgren@bredband.net>
*
* 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 nsHTMLLegendElement_h___
#define nsHTMLLegendElement_h___
#include "nsIDOMHTMLLegendElement.h"
#include "nsGenericHTMLElement.h"
class nsHTMLLegendElement : public nsGenericHTMLElement,
public nsIDOMHTMLLegendElement
{
public:
nsHTMLLegendElement(nsINodeInfo *aNodeInfo);
virtual ~nsHTMLLegendElement();
static nsHTMLLegendElement* FromContent(nsIContent *aContent)
{
if (aContent->IsHTML() && aContent->Tag() == nsGkAtoms::legend)
return static_cast<nsHTMLLegendElement*>(aContent);
return nsnull;
}
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
// nsIDOMNode
NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
// nsIDOMElement
NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
// nsIDOMHTMLElement
NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
// nsIDOMHTMLLegendElement
NS_DECL_NSIDOMHTMLLEGENDELEMENT
// nsGenericHTMLElement
NS_IMETHODIMP Focus();
virtual void PerformAccesskey(PRBool aKeyCausesActivation,
PRBool aIsTrustedEvent);
// nsIContent
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
nsIContent* aBindingParent,
PRBool aCompileEventHandlers);
virtual void UnbindFromTree(PRBool aDeep = PR_TRUE,
PRBool aNullParent = PR_TRUE);
virtual PRBool ParseAttribute(PRInt32 aNamespaceID,
nsIAtom* aAttribute,
const nsAString& aValue,
nsAttrValue& aResult);
virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
PRInt32 aModType) const;
nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString& aValue, PRBool aNotify)
{
return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
}
virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
nsIAtom* aPrefix, const nsAString& aValue,
PRBool aNotify);
virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
PRBool aNotify);
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
mozilla::dom::Element *GetFormElement()
{
nsCOMPtr<nsIFormControl> fieldsetControl = do_QueryInterface(GetFieldSet());
return fieldsetControl ? fieldsetControl->GetFormElement() : nsnull;
}
protected:
/**
* Get the fieldset content element that contains this legend.
* Returns null if there is no fieldset containing this legend.
*/
nsIContent* GetFieldSet();
};
#endif /* nsHTMLLegendElement_h___ */

View File

@ -37,10 +37,13 @@
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsHTMLOptionElement.h"
#include "nsIDOMHTMLOptionElement.h"
#include "nsIDOMNSHTMLOptionElement.h"
#include "nsIOptionElement.h"
#include "nsIDOMHTMLOptGroupElement.h"
#include "nsIDOMHTMLFormElement.h"
#include "nsIDOMEventTarget.h"
#include "nsGenericHTMLElement.h"
#include "nsGkAtoms.h"
#include "nsStyleConsts.h"
#include "nsIFormControl.h"
@ -49,6 +52,7 @@
#include "nsIDOMNode.h"
#include "nsGenericElement.h"
#include "nsIDOMHTMLCollection.h"
#include "nsIJSNativeInitializer.h"
#include "nsISelectElement.h"
#include "nsISelectControlFrame.h"
@ -65,6 +69,74 @@
#include "nsContentCreatorFunctions.h"
#include "mozAutoDocUpdate.h"
/**
* Implementation of &lt;option&gt;
*/
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)
{
@ -129,8 +201,7 @@ nsHTMLOptionElement::GetForm(nsIDOMHTMLFormElement** aForm)
NS_ENSURE_ARG_POINTER(aForm);
*aForm = nsnull;
nsCOMPtr<nsIDOMHTMLSelectElement> selectControl =
do_QueryInterface(GetSelect());
nsCOMPtr<nsIFormControl> selectControl = do_QueryInterface(GetSelect());
if (selectControl) {
selectControl->GetForm(aForm);

View File

@ -1,126 +0,0 @@
/* -*- 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 <pp@ludusdesign.com>
* Mats Palmgren <mats.palmgren@bredband.net>
*
* 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 "nsIDOMHTMLOptionElement.h"
#include "nsIDOMNSHTMLOptionElement.h"
#include "nsIOptionElement.h"
#include "nsGenericHTMLElement.h"
#include "nsIJSNativeInitializer.h"
/**
* Implementation of &lt;option&gt;
*/
class nsHTMLOptionElement : public nsGenericHTMLElement,
public nsIDOMHTMLOptionElement,
public nsIDOMNSHTMLOptionElement,
public nsIJSNativeInitializer,
public nsIOptionElement
{
public:
nsHTMLOptionElement(nsINodeInfo *aNodeInfo);
virtual ~nsHTMLOptionElement();
/** Typesafe, non-refcounting cast from nsIContent. Cheaper than QI. **/
static nsHTMLOptionElement* FromContent(nsIContent *aContent)
{
if (aContent->NodeInfo()->Equals(nsGkAtoms::option, kNameSpaceID_XHTML))
return static_cast<nsHTMLOptionElement*>(aContent);
return nsnull;
}
// 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;
};
#endif

View File

@ -38,7 +38,6 @@
* ***** END LICENSE BLOCK ***** */
#include "nsHTMLSelectElement.h"
#include "nsHTMLOptionElement.h"
#include "nsIDOMEventTarget.h"
#include "nsContentCreatorFunctions.h"
#include "nsGkAtoms.h"
@ -70,9 +69,6 @@
#include "nsServiceManagerUtils.h"
#include "nsRuleData.h"
#include "nsEventDispatcher.h"
#include "mozilla/dom/Element.h"
using namespace mozilla::dom;
NS_IMPL_ISUPPORTS1(nsSelectState, nsSelectState)
NS_DEFINE_STATIC_IID_ACCESSOR(nsSelectState, NS_SELECT_STATE_IID)
@ -355,7 +351,7 @@ nsHTMLSelectElement::InsertOptionsIntoListRecurse(nsIContent* aOptions,
// just not going to look for an option inside of an option.
// Sue me.
nsHTMLOptionElement *optElement = nsHTMLOptionElement::FromContent(aOptions);
nsCOMPtr<nsIDOMHTMLOptionElement> optElement(do_QueryInterface(aOptions));
if (optElement) {
nsresult rv = mOptions->InsertOptionAt(optElement, *aInsertIndex);
NS_ENSURE_SUCCESS(rv, rv);
@ -573,7 +569,7 @@ PRInt32
nsHTMLSelectElement::GetFirstOptionIndex(nsIContent* aOptions)
{
PRInt32 listIndex = -1;
nsHTMLOptionElement *optElement = nsHTMLOptionElement::FromContent(aOptions);
nsCOMPtr<nsIDOMHTMLOptionElement> optElement(do_QueryInterface(aOptions));
if (optElement) {
GetOptionIndex(optElement, 0, PR_TRUE, &listIndex);
// If you nested stuff under the option, you're just plain
@ -675,7 +671,8 @@ nsHTMLSelectElement::Remove(PRInt32 aIndex)
NS_IMETHODIMP
nsHTMLSelectElement::GetOptions(nsIDOMHTMLOptionsCollection** aValue)
{
NS_IF_ADDREF(*aValue = GetOptions());
*aValue = mOptions;
NS_IF_ADDREF(*aValue);
return NS_OK;
}
@ -798,8 +795,7 @@ nsHTMLSelectElement::GetOptionIndex(nsIDOMHTMLOptionElement* aOption,
PRInt32 aStartIndex, PRBool aForward,
PRInt32* aIndex)
{
nsCOMPtr<Element> option = do_QueryInterface(aOption);
return mOptions->GetOptionIndex(option, aStartIndex, aForward, aIndex);
return mOptions->GetOptionIndex(aOption, aStartIndex, aForward, aIndex);
}
PRBool
@ -1703,7 +1699,7 @@ AddOptionsRecurse(nsIContent* aRoot, nsHTMLOptionCollection* aArray)
{
nsIContent* child;
for(PRUint32 i = 0; (child = aRoot->GetChildAt(i)); ++i) {
nsHTMLOptionElement *opt = nsHTMLOptionElement::FromContent(child);
nsCOMPtr<nsIDOMHTMLOptionElement> opt = do_QueryInterface(child);
if (opt) {
// If we fail here, then at least we've tried our best
aArray->AppendOption(opt);
@ -1776,7 +1772,7 @@ nsHTMLOptionCollection::DropReference()
}
nsresult
nsHTMLOptionCollection::GetOptionIndex(mozilla::dom::Element* aOption,
nsHTMLOptionCollection::GetOptionIndex(nsIDOMHTMLOptionElement* aOption,
PRInt32 aStartIndex,
PRBool aForward,
PRInt32* aIndex)
@ -1794,7 +1790,7 @@ nsHTMLOptionCollection::GetOptionIndex(mozilla::dom::Element* aOption,
return NS_OK;
}
PRInt32 high = mElements.Length();
PRInt32 high = mElements.Count();
PRInt32 step = aForward ? 1 : -1;
for (index = aStartIndex; index < high && index > -1; index += step) {
@ -1810,16 +1806,10 @@ nsHTMLOptionCollection::GetOptionIndex(mozilla::dom::Element* aOption,
NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLOptionCollection)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsHTMLOptionCollection)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSTARRAY(mElements)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mElements)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsHTMLOptionCollection)
{
PRUint32 i;
for (i = 0; i < tmp->mElements.Length(); ++i) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mElements[i]");
cb.NoteXPCOMChild(static_cast<Element*>(tmp->mElements[i]));
}
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mElements)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
// nsISupports
@ -1849,7 +1839,7 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsHTMLOptionCollection,
NS_IMETHODIMP
nsHTMLOptionCollection::GetLength(PRUint32* aLength)
{
*aLength = mElements.Length();
*aLength = mElements.Count();
return NS_OK;
}
@ -1883,25 +1873,23 @@ nsHTMLOptionCollection::SetOption(PRInt32 aIndex,
nsresult rv = NS_OK;
PRUint32 index = PRUint32(aIndex);
// Now we're going to be setting an option in our collection
if (index > mElements.Length()) {
if (aIndex > mElements.Count()) {
// Fill our array with blank options up to (but not including, since we're
// about to change it) aIndex, for compat with other browsers.
rv = SetLength(index);
rv = SetLength(aIndex);
NS_ENSURE_SUCCESS(rv, rv);
}
NS_ASSERTION(index <= mElements.Length(), "SetLength lied");
NS_ASSERTION(aIndex <= mElements.Count(), "SetLength lied");
nsCOMPtr<nsIDOMNode> ret;
if (index == mElements.Length()) {
if (aIndex == mElements.Count()) {
rv = mSelect->AppendChild(aOption, getter_AddRefs(ret));
} else {
// Find the option they're talking about and replace it
// hold a strong reference to follow COM rules.
nsCOMPtr<nsIDOMHTMLOptionElement> refChild = ItemAsOption(index);
nsCOMPtr<nsIDOMHTMLOptionElement> refChild = mElements.SafeObjectAt(aIndex);
NS_ENSURE_TRUE(refChild, NS_ERROR_UNEXPECTED);
nsCOMPtr<nsIDOMNode> parent;
@ -1944,22 +1932,14 @@ nsHTMLOptionCollection::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
return CallQueryInterface(item, aReturn);
}
nsISupports*
nsHTMLOptionCollection::GetNodeAt(PRUint32 aIndex, nsresult* aResult)
{
*aResult = NS_OK;
return static_cast<Element*>(ItemAsOption(aIndex));
}
nsISupports*
nsHTMLOptionCollection::GetNamedItem(const nsAString& aName, nsresult* aResult)
{
*aResult = NS_OK;
PRUint32 count = mElements.Length();
for (PRUint32 i = 0; i < count; i++) {
nsIContent *content = ItemAsOption(i);
PRInt32 count = mElements.Count();
for (PRInt32 i = 0; i < count; i++) {
nsCOMPtr<nsIContent> content = do_QueryInterface(mElements.ObjectAt(i));
if (content &&
(content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name, aName,
eCaseMatters) ||

View File

@ -60,7 +60,7 @@
#include "nsIComponentManager.h"
#include "nsCheapSets.h"
#include "nsLayoutErrors.h"
#include "nsHTMLOptionElement.h"
class nsHTMLSelectElement;
@ -87,7 +87,12 @@ public:
// nsIDOMHTMLCollection interface, all its methods are defined in
// nsIDOMHTMLOptionsCollection
virtual nsISupports* GetNodeAt(PRUint32 aIndex, nsresult* aResult);
virtual nsISupports* GetNodeAt(PRUint32 aIndex, nsresult* aResult)
{
*aResult = NS_OK;
return mElements.SafeObjectAt(aIndex);
}
virtual nsISupports* GetNamedItem(const nsAString& aName, nsresult* aResult);
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsHTMLOptionCollection,
@ -99,18 +104,18 @@ public:
* @param aOption the option to insert
* @param aIndex the index to insert at
*/
PRBool InsertOptionAt(nsHTMLOptionElement* aOption, PRUint32 aIndex)
PRBool InsertOptionAt(nsIDOMHTMLOptionElement* aOption, PRInt32 aIndex)
{
return !!mElements.InsertElementAt(aIndex, aOption);
return mElements.InsertObjectAt(aOption, aIndex);
}
/**
* Remove an option
* @param aIndex the index of the option to remove
*/
void RemoveOptionAt(PRUint32 aIndex)
void RemoveOptionAt(PRInt32 aIndex)
{
mElements.RemoveElementAt(aIndex);
mElements.RemoveObjectAt(aIndex);
}
/**
@ -118,9 +123,9 @@ public:
* @param aIndex the index
* @param aReturn the option returned [OUT]
*/
nsHTMLOptionElement *ItemAsOption(PRUint32 aIndex)
nsIDOMHTMLOptionElement *ItemAsOption(PRInt32 aIndex)
{
return mElements.SafeElementAt(aIndex, nsRefPtr<nsHTMLOptionElement>());
return mElements.SafeObjectAt(aIndex);
}
/**
@ -134,9 +139,9 @@ public:
/**
* Append an option to end of array
*/
PRBool AppendOption(nsHTMLOptionElement* aOption)
PRBool AppendOption(nsIDOMHTMLOptionElement* aOption)
{
return !!mElements.AppendElement(aOption);
return mElements.AppendObject(aOption);
}
/**
@ -147,13 +152,13 @@ public:
/**
* See nsISelectElement.idl for documentation on this method
*/
nsresult GetOptionIndex(mozilla::dom::Element* aOption,
nsresult GetOptionIndex(nsIDOMHTMLOptionElement* aOption,
PRInt32 aStartIndex, PRBool aForward,
PRInt32* aIndex);
private:
/** The list of options (holds strong references) */
nsTArray<nsRefPtr<nsHTMLOptionElement> > mElements;
nsCOMArray<nsIDOMHTMLOptionElement> mElements;
/** The select element that contains this array */
nsHTMLSelectElement* mSelect;
};
@ -304,16 +309,6 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLSelectElement,
nsGenericHTMLFormElement)
nsHTMLOptionCollection *GetOptions()
{
return mOptions;
}
static nsHTMLSelectElement *FromSupports(nsISupports *aSupports)
{
return static_cast<nsHTMLSelectElement*>(static_cast<nsINode*>(aSupports));
}
protected:
friend class nsSafeOptionListMutation;

View File

@ -214,7 +214,7 @@
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMDocumentFragment.h"
#include "nsIDOMDocumentEvent.h"
#include "nsDOMAttribute.h"
#include "nsIDOMAttr.h"
#include "nsIDOMText.h"
#include "nsIDOM3Text.h"
#include "nsIDOMComment.h"
@ -476,8 +476,6 @@
#include "nsIEventListenerService.h"
#include "nsIFrameMessageManager.h"
#include "mozilla/dom/Element.h"
#include "nsHTMLSelectElement.h"
#include "nsHTMLLegendElement.h"
using namespace mozilla::dom;
@ -7476,8 +7474,9 @@ nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj,
hasHadScriptHandlingObject ||
IsPrivilegedScript());
nsINode *native_parent;
nsISupports *native_parent;
PRBool slimWrappers = PR_TRUE;
PRBool nodeIsElement = node->IsElement();
if (nodeIsElement && node->AsElement()->IsXUL()) {
// For XUL elements, use the parent, if any.
@ -7500,21 +7499,23 @@ nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj,
nsCOMPtr<nsIFormControl> form_control(do_QueryInterface(node));
if (form_control) {
Element *form = form_control->GetFormElement();
nsCOMPtr<nsIDOMHTMLFormElement> form;
form_control->GetForm(getter_AddRefs(form));
if (form) {
// Found a form, use it.
native_parent = form;
}
}
}
else {
// Legend isn't an HTML form control but should have its fieldset form
// as scope parent at least for backward compatibility.
nsHTMLLegendElement *legend =
nsHTMLLegendElement::FromContent(node->AsElement());
// Legend isn't an HTML form control but should have its fieldset form
// as scope parent at least for backward compatibility.
} else if (node->AsElement()->IsHTML() &&
node->AsElement()->Tag() == nsGkAtoms::legend) {
nsCOMPtr<nsIDOMHTMLLegendElement> legend(do_QueryInterface(node));
if (legend) {
Element *form = legend->GetFormElement();
nsCOMPtr<nsIDOMHTMLFormElement> form;
legend->GetForm(getter_AddRefs(form));
if (form) {
native_parent = form;
@ -7527,27 +7528,19 @@ nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj,
// document's global object, if there is one
// Get the scope object from the document.
nsISupports *scope = doc->GetScopeObject();
native_parent = doc->GetScopeObject();
if (scope) {
jsval v;
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
nsresult rv = WrapNative(cx, globalObj, scope, nsnull, PR_FALSE, &v,
getter_AddRefs(holder));
NS_ENSURE_SUCCESS(rv, rv);
holder->GetJSObject(parentObj);
}
else {
if (!native_parent) {
// No global object reachable from this document, use the
// global object that was passed to this method.
*parentObj = globalObj;
return node->IsInNativeAnonymousSubtree() ?
NS_SUCCESS_CHROME_ACCESS_ONLY : NS_OK;
}
// No slim wrappers for a document's scope object.
return node->IsInNativeAnonymousSubtree() ?
NS_SUCCESS_CHROME_ACCESS_ONLY : NS_OK;
slimWrappers = PR_FALSE;
}
// XXXjst: Maybe we need to find the global to use from the
@ -7555,12 +7548,22 @@ nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj,
// to wrap here? But that's not always reachable, let's use
// globalObj for now...
nsresult rv = WrapNativeParent(cx, globalObj, native_parent, native_parent,
parentObj);
if (native_parent == doc && (*parentObj = doc->GetWrapper()))
return node->IsInNativeAnonymousSubtree() ?
NS_SUCCESS_CHROME_ACCESS_ONLY :
(slimWrappers ? NS_SUCCESS_ALLOW_SLIM_WRAPPERS : NS_OK);
jsval v;
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
nsresult rv = WrapNative(cx, globalObj, native_parent, PR_FALSE, &v,
getter_AddRefs(holder));
NS_ENSURE_SUCCESS(rv, rv);
*parentObj = JSVAL_TO_OBJECT(v);
return node->IsInNativeAnonymousSubtree() ?
NS_SUCCESS_CHROME_ACCESS_ONLY : NS_SUCCESS_ALLOW_SLIM_WRAPPERS;
NS_SUCCESS_CHROME_ACCESS_ONLY :
(slimWrappers ? NS_SUCCESS_ALLOW_SLIM_WRAPPERS : NS_OK);
}
NS_IMETHODIMP
@ -8358,8 +8361,7 @@ nsNamedNodeMapSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
{
nsDOMAttributeMap* map = nsDOMAttributeMap::FromSupports(aNative);
nsINode *attr = map->GetItemAt(aIndex, aResult);
return attr;
return map->GetItemAt(aIndex, aResult);
}
nsISupports*
@ -8368,8 +8370,7 @@ nsNamedNodeMapSH::GetNamedItem(nsISupports *aNative, const nsAString& aName,
{
nsDOMAttributeMap* map = nsDOMAttributeMap::FromSupports(aNative);
nsINode *attr = map->GetNamedItem(aName, aResult);
return attr;
return map->GetNamedItem(aName, aResult);
}
@ -9524,13 +9525,15 @@ nsHTMLSelectElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
nsresult rv = NS_OK;
if (n >= 0) {
nsHTMLSelectElement *s =
nsHTMLSelectElement::FromSupports(GetNative(wrapper, obj));
nsCOMPtr<nsIDOMHTMLSelectElement> s = do_QueryWrappedNative(wrapper, obj);
nsHTMLOptionCollection *options = s->GetOptions();
nsCOMPtr<nsIDOMHTMLOptionsCollection> options;
s->GetOptions(getter_AddRefs(options));
if (options) {
nsISupports *node = options->GetNodeAt(n, &rv);
nsCOMPtr<nsIDOMNode> node;
options->Item(n, getter_AddRefs(node));
rv = WrapNative(cx, obj, node, &NS_GET_IID(nsIDOMNode), PR_TRUE, vp);
if (NS_SUCCEEDED(rv)) {