mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
Merge
This commit is contained in:
commit
df2f1f7fff
@ -2188,9 +2188,7 @@ nsAccessible::GetRelationByType(PRUint32 aRelationType,
|
||||
// HTML form controls implements nsIFormControl interface.
|
||||
nsCOMPtr<nsIFormControl> control(do_QueryInterface(mContent));
|
||||
if (control) {
|
||||
nsCOMPtr<nsIDOMHTMLFormElement> htmlform;
|
||||
control->GetForm(getter_AddRefs(htmlform));
|
||||
nsCOMPtr<nsIForm> form(do_QueryInterface(htmlform));
|
||||
nsCOMPtr<nsIForm> form(do_QueryInterface(control->GetFormElement()));
|
||||
if (form) {
|
||||
nsCOMPtr<nsIContent> formContent =
|
||||
do_QueryInterface(form->GetDefaultSubmitElement());
|
||||
|
@ -170,15 +170,11 @@ 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++) {
|
||||
aContentList.Item(i, getter_AddRefs(item));
|
||||
|
||||
nsCOMPtr<nsIContent> c(do_QueryInterface(item));
|
||||
|
||||
nsIContent *c = aContentList.GetNodeAt(i);
|
||||
if (c && nsContentUtils::BelongsInForm(aForm, c)) {
|
||||
AppendElement(c);
|
||||
}
|
||||
|
@ -1914,11 +1914,10 @@ static inline void KeyAppendAtom(nsIAtom* aAtom, nsACString& aKey)
|
||||
KeyAppendString(nsAtomCString(aAtom), aKey);
|
||||
}
|
||||
|
||||
static inline PRBool IsAutocompleteOff(nsIDOMElement* aElement)
|
||||
static inline PRBool IsAutocompleteOff(nsIContent* aElement)
|
||||
{
|
||||
nsAutoString autocomplete;
|
||||
aElement->GetAttribute(NS_LITERAL_STRING("autocomplete"), autocomplete);
|
||||
return autocomplete.LowerCaseEqualsLiteral("off");
|
||||
return aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::autocomplete,
|
||||
NS_LITERAL_STRING("off"), eIgnoreCase);
|
||||
}
|
||||
|
||||
/*static*/ nsresult
|
||||
@ -1947,8 +1946,7 @@ nsContentUtils::GenerateStateKey(nsIContent* aContent,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(aContent));
|
||||
if (element && IsAutocompleteOff(element)) {
|
||||
if (IsAutocompleteOff(aContent)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -1994,10 +1992,8 @@ nsContentUtils::GenerateStateKey(nsIContent* aContent,
|
||||
|
||||
// If in a form, add form name / index of form / index in form
|
||||
PRInt32 index = -1;
|
||||
nsCOMPtr<nsIDOMHTMLFormElement> formElement;
|
||||
control->GetForm(getter_AddRefs(formElement));
|
||||
Element *formElement = control->GetFormElement();
|
||||
if (formElement) {
|
||||
|
||||
if (IsAutocompleteOff(formElement)) {
|
||||
aKey.Truncate();
|
||||
return NS_OK;
|
||||
@ -2006,8 +2002,7 @@ nsContentUtils::GenerateStateKey(nsIContent* aContent,
|
||||
KeyAppendString(NS_LITERAL_CSTRING("f"), aKey);
|
||||
|
||||
// Append the index of the form in the document
|
||||
nsCOMPtr<nsIContent> formContent(do_QueryInterface(formElement));
|
||||
index = htmlForms->IndexOf(formContent, PR_FALSE);
|
||||
index = htmlForms->IndexOf(formElement, PR_FALSE);
|
||||
if (index <= -1) {
|
||||
//
|
||||
// XXX HACK this uses some state that was dumped into the document
|
||||
@ -2033,7 +2028,7 @@ nsContentUtils::GenerateStateKey(nsIContent* aContent,
|
||||
|
||||
// Append the form name
|
||||
nsAutoString formName;
|
||||
formElement->GetName(formName);
|
||||
formElement->GetAttr(kNameSpaceID_None, nsGkAtoms::name, formName);
|
||||
KeyAppendString(formName, aKey);
|
||||
|
||||
} else {
|
||||
|
@ -72,11 +72,10 @@ nsDOMAttributeMap::Init()
|
||||
* Clear map pointer for attributes.
|
||||
*/
|
||||
PLDHashOperator
|
||||
RemoveMapRef(nsAttrHashKey::KeyType aKey, nsCOMPtr<nsIDOMNode>& aData, void* aUserArg)
|
||||
RemoveMapRef(nsAttrHashKey::KeyType aKey, nsRefPtr<nsDOMAttribute>& aData,
|
||||
void* aUserArg)
|
||||
{
|
||||
nsCOMPtr<nsIAttribute> attr(do_QueryInterface(aData));
|
||||
NS_ASSERTION(attr, "non-nsIAttribute somehow made it into the hashmap?!");
|
||||
attr->SetMap(nsnull);
|
||||
aData->SetMap(nsnull);
|
||||
|
||||
return PL_DHASH_REMOVE;
|
||||
}
|
||||
@ -101,12 +100,13 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
|
||||
PLDHashOperator
|
||||
TraverseMapEntry(nsAttrHashKey::KeyType aKey, nsCOMPtr<nsIDOMNode>& aData, void* aUserArg)
|
||||
TraverseMapEntry(nsAttrHashKey::KeyType aKey, nsRefPtr<nsDOMAttribute>& aData,
|
||||
void* aUserArg)
|
||||
{
|
||||
nsCycleCollectionTraversalCallback *cb =
|
||||
static_cast<nsCycleCollectionTraversalCallback*>(aUserArg);
|
||||
|
||||
cb->NoteXPCOMChild(aData.get());
|
||||
cb->NoteXPCOMChild(static_cast<nsINode*>(aData.get()));
|
||||
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
@ -131,12 +131,11 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMAttributeMap)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMAttributeMap)
|
||||
|
||||
PLDHashOperator
|
||||
SetOwnerDocumentFunc(nsAttrHashKey::KeyType aKey, nsCOMPtr<nsIDOMNode>& aData,
|
||||
SetOwnerDocumentFunc(nsAttrHashKey::KeyType aKey,
|
||||
nsRefPtr<nsDOMAttribute>& aData,
|
||||
void* 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));
|
||||
nsresult rv = aData->SetOwnerDocument(static_cast<nsIDocument*>(aUserArg));
|
||||
|
||||
return NS_FAILED(rv) ? PL_DHASH_STOP : PL_DHASH_NEXT;
|
||||
}
|
||||
@ -154,13 +153,10 @@ void
|
||||
nsDOMAttributeMap::DropAttribute(PRInt32 aNamespaceID, nsIAtom* aLocalName)
|
||||
{
|
||||
nsAttrKey attr(aNamespaceID, aLocalName);
|
||||
nsIDOMNode *node = mAttributeCache.GetWeak(attr);
|
||||
nsDOMAttribute *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
|
||||
iAttr->SetMap(nsnull);
|
||||
node->SetMap(nsnull);
|
||||
|
||||
// Remove from cache
|
||||
mAttributeCache.Remove(attr);
|
||||
@ -177,7 +173,8 @@ nsDOMAttributeMap::RemoveAttribute(nsINodeInfo* aNodeInfo, nsIDOMNode** aReturn)
|
||||
|
||||
nsAttrKey attr(aNodeInfo->NamespaceID(), aNodeInfo->NameAtom());
|
||||
|
||||
if (!mAttributeCache.Get(attr, aReturn)) {
|
||||
nsRefPtr<nsDOMAttribute> node;
|
||||
if (!mAttributeCache.Get(attr, getter_AddRefs(node))) {
|
||||
nsAutoString value;
|
||||
// As we are removing the attribute we need to set the current value in
|
||||
// the attribute node.
|
||||
@ -189,29 +186,28 @@ 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
|
||||
iAttr->SetMap(nsnull);
|
||||
node->SetMap(nsnull);
|
||||
|
||||
// Remove from cache
|
||||
mAttributeCache.Remove(attr);
|
||||
|
||||
node.forget(aReturn);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIDOMNode*
|
||||
nsDOMAttribute*
|
||||
nsDOMAttributeMap::GetAttribute(nsINodeInfo* aNodeInfo)
|
||||
{
|
||||
NS_ASSERTION(aNodeInfo, "GetAttribute() called with aNodeInfo == nsnull!");
|
||||
|
||||
nsAttrKey attr(aNodeInfo->NamespaceID(), aNodeInfo->NameAtom());
|
||||
|
||||
nsIDOMNode* node = mAttributeCache.GetWeak(attr);
|
||||
nsDOMAttribute* node = mAttributeCache.GetWeak(attr);
|
||||
if (!node) {
|
||||
nsCOMPtr<nsIDOMNode> newAttr =
|
||||
nsRefPtr<nsDOMAttribute> newAttr =
|
||||
new nsDOMAttribute(this, aNodeInfo, EmptyString());
|
||||
if (newAttr && mAttributeCache.Put(attr, newAttr)) {
|
||||
node = newAttr;
|
||||
@ -221,7 +217,7 @@ nsDOMAttributeMap::GetAttribute(nsINodeInfo* aNodeInfo)
|
||||
return node;
|
||||
}
|
||||
|
||||
nsIDOMNode*
|
||||
nsDOMAttribute*
|
||||
nsDOMAttributeMap::GetNamedItem(const nsAString& aAttrName, nsresult *aResult)
|
||||
{
|
||||
*aResult = NS_OK;
|
||||
@ -230,12 +226,7 @@ nsDOMAttributeMap::GetNamedItem(const nsAString& aAttrName, nsresult *aResult)
|
||||
nsCOMPtr<nsINodeInfo> ni =
|
||||
mContent->GetExistingAttrNameFromQName(aAttrName);
|
||||
if (ni) {
|
||||
nsIDOMNode* node = GetAttribute(ni);
|
||||
if (node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
*aResult = NS_ERROR_OUT_OF_MEMORY;
|
||||
return GetAttribute(ni);
|
||||
}
|
||||
}
|
||||
|
||||
@ -282,12 +273,13 @@ 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 (!attribute || !iAttribute) {
|
||||
if (!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) {
|
||||
@ -389,8 +381,7 @@ nsDOMAttributeMap::RemoveNamedItem(const nsAString& aName,
|
||||
return NS_ERROR_DOM_NOT_FOUND_ERR;
|
||||
}
|
||||
|
||||
rv = GetAttribute(ni, aReturn);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ADDREF(*aReturn = GetAttribute(ni));
|
||||
|
||||
// This removes the attribute node from the attribute map.
|
||||
rv = mContent->UnsetAttr(ni->NamespaceID(), ni->NameAtom(), PR_TRUE);
|
||||
@ -400,12 +391,12 @@ nsDOMAttributeMap::RemoveNamedItem(const nsAString& aName,
|
||||
}
|
||||
|
||||
|
||||
nsIDOMNode*
|
||||
nsDOMAttribute*
|
||||
nsDOMAttributeMap::GetItemAt(PRUint32 aIndex, nsresult *aResult)
|
||||
{
|
||||
*aResult = NS_OK;
|
||||
|
||||
nsIDOMNode* node = nsnull;
|
||||
nsDOMAttribute* node = nsnull;
|
||||
|
||||
const nsAttrName* name;
|
||||
if (mContent && (name = mContent->GetAttrNameAt(aIndex))) {
|
||||
@ -417,7 +408,7 @@ nsDOMAttributeMap::GetItemAt(PRUint32 aIndex, nsresult *aResult)
|
||||
if (ni) {
|
||||
node = GetAttribute(ni);
|
||||
}
|
||||
if (!node) {
|
||||
else {
|
||||
*aResult = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
@ -493,7 +484,11 @@ nsDOMAttributeMap::GetNamedItemNSInternal(const nsAString& aNamespaceURI,
|
||||
GetNodeInfo(nameAtom, name->GetPrefix(), nameSpaceID);
|
||||
NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
return aRemove ? RemoveAttribute(ni, aReturn) : GetAttribute(ni, aReturn);
|
||||
if (aRemove) {
|
||||
return RemoveAttribute(ni, aReturn);
|
||||
}
|
||||
|
||||
NS_ADDREF(*aReturn = GetAttribute(ni));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@
|
||||
|
||||
#include "nsIDOMNamedNodeMap.h"
|
||||
#include "nsString.h"
|
||||
#include "nsInterfaceHashtable.h"
|
||||
#include "nsRefPtrHashtable.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "prbit.h"
|
||||
#include "nsIDOMNode.h"
|
||||
@ -160,7 +160,7 @@ public:
|
||||
*/
|
||||
PRUint32 Count() const;
|
||||
|
||||
typedef nsInterfaceHashtable<nsAttrHashKey, nsIDOMNode> AttrCache;
|
||||
typedef nsRefPtrHashtable<nsAttrHashKey, nsDOMAttribute> 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;
|
||||
|
||||
nsIDOMNode* GetItemAt(PRUint32 aIndex, nsresult *rv);
|
||||
nsIDOMNode* GetNamedItem(const nsAString& aAttrName, nsresult *rv);
|
||||
nsDOMAttribute* GetItemAt(PRUint32 aIndex, nsresult *rv);
|
||||
nsDOMAttribute* GetNamedItem(const nsAString& aAttrName, nsresult *rv);
|
||||
|
||||
static nsDOMAttributeMap* FromSupports(nsISupports* aSupports)
|
||||
{
|
||||
@ -217,24 +217,7 @@ private:
|
||||
nsIDOMNode** aReturn,
|
||||
PRBool aRemove = PR_FALSE);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
nsDOMAttribute* GetAttribute(nsINodeInfo* aNodeInfo);
|
||||
|
||||
/**
|
||||
* Remove an attribute, returns the removed node.
|
||||
|
@ -5619,12 +5619,12 @@ nsDocument::SetDocumentURI(const nsAString& aDocumentURI)
|
||||
static void BlastSubtreeToPieces(nsINode *aNode);
|
||||
|
||||
PLDHashOperator
|
||||
BlastFunc(nsAttrHashKey::KeyType aKey, nsIDOMNode *aData, void* aUserArg)
|
||||
BlastFunc(nsAttrHashKey::KeyType aKey, nsDOMAttribute *aData, void* aUserArg)
|
||||
{
|
||||
nsCOMPtr<nsIAttribute> *attr =
|
||||
static_cast<nsCOMPtr<nsIAttribute>*>(aUserArg);
|
||||
|
||||
*attr = do_QueryInterface(aData);
|
||||
*attr = aData;
|
||||
|
||||
NS_ASSERTION(attr->get(),
|
||||
"non-nsIAttribute somehow made it into the hashmap?!");
|
||||
|
@ -38,14 +38,13 @@
|
||||
#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;
|
||||
@ -250,9 +249,6 @@ 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
|
||||
|
@ -45,6 +45,12 @@ 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,
|
||||
@ -93,8 +99,8 @@ PR_STATIC_ASSERT((PRUint32)eButtonElementTypesMax < (PRUint32)NS_FORM_INPUT_ELEM
|
||||
PR_STATIC_ASSERT((PRUint32)eInputElementTypesMax < 1<<8);
|
||||
|
||||
#define NS_IFORMCONTROL_IID \
|
||||
{ 0x52dc1f0d, 0x1683, 0x4dd7, \
|
||||
{ 0xae, 0x0a, 0xc4, 0x76, 0x10, 0x64, 0x2f, 0xa8 } }
|
||||
{ 0x0dc5083b, 0xb0a8, 0x48c4, \
|
||||
{ 0xb2, 0xeb, 0xc2, 0x4f, 0xfb, 0x7e, 0xc2, 0x8e } }
|
||||
|
||||
/**
|
||||
* Interface which all form controls (e.g. buttons, checkboxes, text,
|
||||
@ -109,9 +115,9 @@ public:
|
||||
|
||||
/**
|
||||
* Get the form for this form control.
|
||||
* @param aForm the form [OUT]
|
||||
* @return the form
|
||||
*/
|
||||
NS_IMETHOD GetForm(nsIDOMHTMLFormElement** aForm) = 0;
|
||||
virtual mozilla::dom::Element *GetFormElement() = 0;
|
||||
|
||||
/**
|
||||
* Set the form for this form control.
|
||||
|
@ -111,6 +111,9 @@
|
||||
#include "mozAutoDocUpdate.h"
|
||||
#include "nsHtml5Module.h"
|
||||
#include "nsITextControlElement.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
@ -2379,7 +2382,13 @@ nsGenericHTMLFormElement::ClearForm(PRBool aRemoveFromForm,
|
||||
mForm = nsnull;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
Element*
|
||||
nsGenericHTMLFormElement::GetFormElement()
|
||||
{
|
||||
return mForm;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericHTMLFormElement::GetForm(nsIDOMHTMLFormElement** aForm)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aForm);
|
||||
|
@ -803,10 +803,12 @@ public:
|
||||
virtual void SaveSubtreeState();
|
||||
|
||||
// nsIFormControl
|
||||
NS_IMETHOD GetForm(nsIDOMHTMLFormElement** aForm);
|
||||
virtual mozilla::dom::Element* GetFormElement();
|
||||
virtual void SetForm(nsIDOMHTMLFormElement* aForm);
|
||||
virtual void ClearForm(PRBool aRemoveFromForm, PRBool aNotify);
|
||||
|
||||
nsresult GetForm(nsIDOMHTMLFormElement** aForm);
|
||||
|
||||
NS_IMETHOD SaveState()
|
||||
{
|
||||
return NS_OK;
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsInterfaceHashtable.h"
|
||||
|
||||
class nsFormControlList;
|
||||
|
||||
|
@ -35,10 +35,9 @@
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsIDOMHTMLLegendElement.h"
|
||||
#include "nsHTMLLegendElement.h"
|
||||
#include "nsIDOMHTMLFormElement.h"
|
||||
#include "nsIDOMEventTarget.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsIForm.h"
|
||||
@ -49,68 +48,6 @@
|
||||
#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)
|
||||
|
||||
|
||||
@ -147,11 +84,9 @@ NS_IMPL_ELEMENT_CLONE(nsHTMLLegendElement)
|
||||
NS_IMETHODIMP
|
||||
nsHTMLLegendElement::GetForm(nsIDOMHTMLFormElement** aForm)
|
||||
{
|
||||
*aForm = nsnull;
|
||||
Element *form = GetFormElement();
|
||||
|
||||
nsCOMPtr<nsIFormControl> fieldsetControl = do_QueryInterface(GetFieldSet());
|
||||
|
||||
return fieldsetControl ? fieldsetControl->GetForm(aForm) : NS_OK;
|
||||
return form ? CallQueryInterface(form, aForm) : NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
119
content/html/content/src/nsHTMLLegendElement.h
Normal file
119
content/html/content/src/nsHTMLLegendElement.h
Normal file
@ -0,0 +1,119 @@
|
||||
/* -*- 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___ */
|
@ -37,13 +37,10 @@
|
||||
* 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 +49,6 @@
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsGenericElement.h"
|
||||
#include "nsIDOMHTMLCollection.h"
|
||||
#include "nsIJSNativeInitializer.h"
|
||||
#include "nsISelectElement.h"
|
||||
#include "nsISelectControlFrame.h"
|
||||
|
||||
@ -69,74 +65,6 @@
|
||||
#include "nsContentCreatorFunctions.h"
|
||||
#include "mozAutoDocUpdate.h"
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
@ -201,7 +129,8 @@ nsHTMLOptionElement::GetForm(nsIDOMHTMLFormElement** aForm)
|
||||
NS_ENSURE_ARG_POINTER(aForm);
|
||||
*aForm = nsnull;
|
||||
|
||||
nsCOMPtr<nsIFormControl> selectControl = do_QueryInterface(GetSelect());
|
||||
nsCOMPtr<nsIDOMHTMLSelectElement> selectControl =
|
||||
do_QueryInterface(GetSelect());
|
||||
|
||||
if (selectControl) {
|
||||
selectControl->GetForm(aForm);
|
||||
|
126
content/html/content/src/nsHTMLOptionElement.h
Normal file
126
content/html/content/src/nsHTMLOptionElement.h
Normal file
@ -0,0 +1,126 @@
|
||||
/* -*- 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 <option>
|
||||
*/
|
||||
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
|
@ -38,6 +38,7 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsHTMLSelectElement.h"
|
||||
#include "nsHTMLOptionElement.h"
|
||||
#include "nsIDOMEventTarget.h"
|
||||
#include "nsContentCreatorFunctions.h"
|
||||
#include "nsGkAtoms.h"
|
||||
@ -69,6 +70,9 @@
|
||||
#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)
|
||||
@ -351,7 +355,7 @@ nsHTMLSelectElement::InsertOptionsIntoListRecurse(nsIContent* aOptions,
|
||||
// just not going to look for an option inside of an option.
|
||||
// Sue me.
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLOptionElement> optElement(do_QueryInterface(aOptions));
|
||||
nsHTMLOptionElement *optElement = nsHTMLOptionElement::FromContent(aOptions);
|
||||
if (optElement) {
|
||||
nsresult rv = mOptions->InsertOptionAt(optElement, *aInsertIndex);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@ -569,7 +573,7 @@ PRInt32
|
||||
nsHTMLSelectElement::GetFirstOptionIndex(nsIContent* aOptions)
|
||||
{
|
||||
PRInt32 listIndex = -1;
|
||||
nsCOMPtr<nsIDOMHTMLOptionElement> optElement(do_QueryInterface(aOptions));
|
||||
nsHTMLOptionElement *optElement = nsHTMLOptionElement::FromContent(aOptions);
|
||||
if (optElement) {
|
||||
GetOptionIndex(optElement, 0, PR_TRUE, &listIndex);
|
||||
// If you nested stuff under the option, you're just plain
|
||||
@ -671,8 +675,7 @@ nsHTMLSelectElement::Remove(PRInt32 aIndex)
|
||||
NS_IMETHODIMP
|
||||
nsHTMLSelectElement::GetOptions(nsIDOMHTMLOptionsCollection** aValue)
|
||||
{
|
||||
*aValue = mOptions;
|
||||
NS_IF_ADDREF(*aValue);
|
||||
NS_IF_ADDREF(*aValue = GetOptions());
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -795,7 +798,8 @@ nsHTMLSelectElement::GetOptionIndex(nsIDOMHTMLOptionElement* aOption,
|
||||
PRInt32 aStartIndex, PRBool aForward,
|
||||
PRInt32* aIndex)
|
||||
{
|
||||
return mOptions->GetOptionIndex(aOption, aStartIndex, aForward, aIndex);
|
||||
nsCOMPtr<Element> option = do_QueryInterface(aOption);
|
||||
return mOptions->GetOptionIndex(option, aStartIndex, aForward, aIndex);
|
||||
}
|
||||
|
||||
PRBool
|
||||
@ -1699,7 +1703,7 @@ AddOptionsRecurse(nsIContent* aRoot, nsHTMLOptionCollection* aArray)
|
||||
{
|
||||
nsIContent* child;
|
||||
for(PRUint32 i = 0; (child = aRoot->GetChildAt(i)); ++i) {
|
||||
nsCOMPtr<nsIDOMHTMLOptionElement> opt = do_QueryInterface(child);
|
||||
nsHTMLOptionElement *opt = nsHTMLOptionElement::FromContent(child);
|
||||
if (opt) {
|
||||
// If we fail here, then at least we've tried our best
|
||||
aArray->AppendOption(opt);
|
||||
@ -1772,7 +1776,7 @@ nsHTMLOptionCollection::DropReference()
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHTMLOptionCollection::GetOptionIndex(nsIDOMHTMLOptionElement* aOption,
|
||||
nsHTMLOptionCollection::GetOptionIndex(mozilla::dom::Element* aOption,
|
||||
PRInt32 aStartIndex,
|
||||
PRBool aForward,
|
||||
PRInt32* aIndex)
|
||||
@ -1790,7 +1794,7 @@ nsHTMLOptionCollection::GetOptionIndex(nsIDOMHTMLOptionElement* aOption,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32 high = mElements.Count();
|
||||
PRInt32 high = mElements.Length();
|
||||
PRInt32 step = aForward ? 1 : -1;
|
||||
|
||||
for (index = aStartIndex; index < high && index > -1; index += step) {
|
||||
@ -1806,10 +1810,16 @@ nsHTMLOptionCollection::GetOptionIndex(nsIDOMHTMLOptionElement* aOption,
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLOptionCollection)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsHTMLOptionCollection)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mElements)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSTARRAY(mElements)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsHTMLOptionCollection)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mElements)
|
||||
{
|
||||
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_END
|
||||
|
||||
// nsISupports
|
||||
@ -1839,7 +1849,7 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsHTMLOptionCollection,
|
||||
NS_IMETHODIMP
|
||||
nsHTMLOptionCollection::GetLength(PRUint32* aLength)
|
||||
{
|
||||
*aLength = mElements.Count();
|
||||
*aLength = mElements.Length();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1861,7 +1871,7 @@ nsHTMLOptionCollection::SetOption(PRInt32 aIndex,
|
||||
if (aIndex < 0 || !mSelect) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// if the new option is null, just remove this option. Note that it's safe
|
||||
// to pass a too-large aIndex in here.
|
||||
if (!aOption) {
|
||||
@ -1873,23 +1883,25 @@ 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 (aIndex > mElements.Count()) {
|
||||
if (index > mElements.Length()) {
|
||||
// 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(aIndex);
|
||||
rv = SetLength(index);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
NS_ASSERTION(aIndex <= mElements.Count(), "SetLength lied");
|
||||
NS_ASSERTION(index <= mElements.Length(), "SetLength lied");
|
||||
|
||||
nsCOMPtr<nsIDOMNode> ret;
|
||||
if (aIndex == mElements.Count()) {
|
||||
if (index == mElements.Length()) {
|
||||
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 = mElements.SafeObjectAt(aIndex);
|
||||
nsCOMPtr<nsIDOMHTMLOptionElement> refChild = ItemAsOption(index);
|
||||
NS_ENSURE_TRUE(refChild, NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> parent;
|
||||
@ -1932,14 +1944,22 @@ 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;
|
||||
|
||||
PRInt32 count = mElements.Count();
|
||||
for (PRInt32 i = 0; i < count; i++) {
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(mElements.ObjectAt(i));
|
||||
PRUint32 count = mElements.Length();
|
||||
for (PRUint32 i = 0; i < count; i++) {
|
||||
nsIContent *content = ItemAsOption(i);
|
||||
if (content &&
|
||||
(content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name, aName,
|
||||
eCaseMatters) ||
|
||||
|
@ -60,7 +60,7 @@
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsCheapSets.h"
|
||||
#include "nsLayoutErrors.h"
|
||||
|
||||
#include "nsHTMLOptionElement.h"
|
||||
|
||||
class nsHTMLSelectElement;
|
||||
|
||||
@ -87,12 +87,7 @@ public:
|
||||
// nsIDOMHTMLCollection interface, all its methods are defined in
|
||||
// nsIDOMHTMLOptionsCollection
|
||||
|
||||
virtual nsISupports* GetNodeAt(PRUint32 aIndex, nsresult* aResult)
|
||||
{
|
||||
*aResult = NS_OK;
|
||||
|
||||
return mElements.SafeObjectAt(aIndex);
|
||||
}
|
||||
virtual nsISupports* GetNodeAt(PRUint32 aIndex, nsresult* aResult);
|
||||
virtual nsISupports* GetNamedItem(const nsAString& aName, nsresult* aResult);
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsHTMLOptionCollection,
|
||||
@ -104,18 +99,18 @@ public:
|
||||
* @param aOption the option to insert
|
||||
* @param aIndex the index to insert at
|
||||
*/
|
||||
PRBool InsertOptionAt(nsIDOMHTMLOptionElement* aOption, PRInt32 aIndex)
|
||||
PRBool InsertOptionAt(nsHTMLOptionElement* aOption, PRUint32 aIndex)
|
||||
{
|
||||
return mElements.InsertObjectAt(aOption, aIndex);
|
||||
return !!mElements.InsertElementAt(aIndex, aOption);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an option
|
||||
* @param aIndex the index of the option to remove
|
||||
*/
|
||||
void RemoveOptionAt(PRInt32 aIndex)
|
||||
void RemoveOptionAt(PRUint32 aIndex)
|
||||
{
|
||||
mElements.RemoveObjectAt(aIndex);
|
||||
mElements.RemoveElementAt(aIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -123,9 +118,9 @@ public:
|
||||
* @param aIndex the index
|
||||
* @param aReturn the option returned [OUT]
|
||||
*/
|
||||
nsIDOMHTMLOptionElement *ItemAsOption(PRInt32 aIndex)
|
||||
nsHTMLOptionElement *ItemAsOption(PRUint32 aIndex)
|
||||
{
|
||||
return mElements.SafeObjectAt(aIndex);
|
||||
return mElements.SafeElementAt(aIndex, nsRefPtr<nsHTMLOptionElement>());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,9 +134,9 @@ public:
|
||||
/**
|
||||
* Append an option to end of array
|
||||
*/
|
||||
PRBool AppendOption(nsIDOMHTMLOptionElement* aOption)
|
||||
PRBool AppendOption(nsHTMLOptionElement* aOption)
|
||||
{
|
||||
return mElements.AppendObject(aOption);
|
||||
return !!mElements.AppendElement(aOption);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,13 +147,13 @@ public:
|
||||
/**
|
||||
* See nsISelectElement.idl for documentation on this method
|
||||
*/
|
||||
nsresult GetOptionIndex(nsIDOMHTMLOptionElement* aOption,
|
||||
nsresult GetOptionIndex(mozilla::dom::Element* aOption,
|
||||
PRInt32 aStartIndex, PRBool aForward,
|
||||
PRInt32* aIndex);
|
||||
|
||||
private:
|
||||
/** The list of options (holds strong references) */
|
||||
nsCOMArray<nsIDOMHTMLOptionElement> mElements;
|
||||
nsTArray<nsRefPtr<nsHTMLOptionElement> > mElements;
|
||||
/** The select element that contains this array */
|
||||
nsHTMLSelectElement* mSelect;
|
||||
};
|
||||
@ -309,6 +304,16 @@ 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;
|
||||
|
||||
|
@ -214,7 +214,7 @@
|
||||
#include "nsIDOMDOMImplementation.h"
|
||||
#include "nsIDOMDocumentFragment.h"
|
||||
#include "nsIDOMDocumentEvent.h"
|
||||
#include "nsIDOMAttr.h"
|
||||
#include "nsDOMAttribute.h"
|
||||
#include "nsIDOMText.h"
|
||||
#include "nsIDOM3Text.h"
|
||||
#include "nsIDOMComment.h"
|
||||
@ -476,6 +476,8 @@
|
||||
#include "nsIEventListenerService.h"
|
||||
#include "nsIFrameMessageManager.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "nsHTMLSelectElement.h"
|
||||
#include "nsHTMLLegendElement.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
|
||||
@ -7474,9 +7476,8 @@ nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj,
|
||||
hasHadScriptHandlingObject ||
|
||||
IsPrivilegedScript());
|
||||
|
||||
nsISupports *native_parent;
|
||||
nsINode *native_parent;
|
||||
|
||||
PRBool slimWrappers = PR_TRUE;
|
||||
PRBool nodeIsElement = node->IsElement();
|
||||
if (nodeIsElement && node->AsElement()->IsXUL()) {
|
||||
// For XUL elements, use the parent, if any.
|
||||
@ -7499,23 +7500,21 @@ nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj,
|
||||
nsCOMPtr<nsIFormControl> form_control(do_QueryInterface(node));
|
||||
|
||||
if (form_control) {
|
||||
nsCOMPtr<nsIDOMHTMLFormElement> form;
|
||||
form_control->GetForm(getter_AddRefs(form));
|
||||
Element *form = form_control->GetFormElement();
|
||||
|
||||
if (form) {
|
||||
// Found a form, use it.
|
||||
native_parent = form;
|
||||
}
|
||||
}
|
||||
// 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));
|
||||
|
||||
}
|
||||
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());
|
||||
if (legend) {
|
||||
nsCOMPtr<nsIDOMHTMLFormElement> form;
|
||||
legend->GetForm(getter_AddRefs(form));
|
||||
Element *form = legend->GetFormElement();
|
||||
|
||||
if (form) {
|
||||
native_parent = form;
|
||||
@ -7528,19 +7527,27 @@ nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj,
|
||||
// document's global object, if there is one
|
||||
|
||||
// Get the scope object from the document.
|
||||
native_parent = doc->GetScopeObject();
|
||||
nsISupports *scope = doc->GetScopeObject();
|
||||
|
||||
if (!native_parent) {
|
||||
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 {
|
||||
// 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;
|
||||
}
|
||||
|
||||
slimWrappers = PR_FALSE;
|
||||
// No slim wrappers for a document's scope object.
|
||||
return node->IsInNativeAnonymousSubtree() ?
|
||||
NS_SUCCESS_CHROME_ACCESS_ONLY : NS_OK;
|
||||
}
|
||||
|
||||
// XXXjst: Maybe we need to find the global to use from the
|
||||
@ -7548,22 +7555,12 @@ nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj,
|
||||
// to wrap here? But that's not always reachable, let's use
|
||||
// globalObj for now...
|
||||
|
||||
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));
|
||||
nsresult rv = WrapNativeParent(cx, globalObj, native_parent, native_parent,
|
||||
parentObj);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
*parentObj = JSVAL_TO_OBJECT(v);
|
||||
|
||||
return node->IsInNativeAnonymousSubtree() ?
|
||||
NS_SUCCESS_CHROME_ACCESS_ONLY :
|
||||
(slimWrappers ? NS_SUCCESS_ALLOW_SLIM_WRAPPERS : NS_OK);
|
||||
NS_SUCCESS_CHROME_ACCESS_ONLY : NS_SUCCESS_ALLOW_SLIM_WRAPPERS;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -8361,7 +8358,8 @@ nsNamedNodeMapSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
|
||||
{
|
||||
nsDOMAttributeMap* map = nsDOMAttributeMap::FromSupports(aNative);
|
||||
|
||||
return map->GetItemAt(aIndex, aResult);
|
||||
nsINode *attr = map->GetItemAt(aIndex, aResult);
|
||||
return attr;
|
||||
}
|
||||
|
||||
nsISupports*
|
||||
@ -8370,7 +8368,8 @@ nsNamedNodeMapSH::GetNamedItem(nsISupports *aNative, const nsAString& aName,
|
||||
{
|
||||
nsDOMAttributeMap* map = nsDOMAttributeMap::FromSupports(aNative);
|
||||
|
||||
return map->GetNamedItem(aName, aResult);
|
||||
nsINode *attr = map->GetNamedItem(aName, aResult);
|
||||
return attr;
|
||||
}
|
||||
|
||||
|
||||
@ -9525,15 +9524,13 @@ nsHTMLSelectElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
if (n >= 0) {
|
||||
nsCOMPtr<nsIDOMHTMLSelectElement> s = do_QueryWrappedNative(wrapper, obj);
|
||||
nsHTMLSelectElement *s =
|
||||
nsHTMLSelectElement::FromSupports(GetNative(wrapper, obj));
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLOptionsCollection> options;
|
||||
s->GetOptions(getter_AddRefs(options));
|
||||
nsHTMLOptionCollection *options = s->GetOptions();
|
||||
|
||||
if (options) {
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
|
||||
options->Item(n, getter_AddRefs(node));
|
||||
nsISupports *node = options->GetNodeAt(n, &rv);
|
||||
|
||||
rv = WrapNative(cx, obj, node, &NS_GET_IID(nsIDOMNode), PR_TRUE, vp);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
Loading…
Reference in New Issue
Block a user