2013-10-03 07:11:26 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_HTMLFormControlsCollection_h
|
|
|
|
#define mozilla_dom_HTMLFormControlsCollection_h
|
|
|
|
|
2013-10-03 07:11:27 +00:00
|
|
|
#include "mozilla/dom/Element.h" // DOMProxyHandler::getOwnPropertyDescriptor
|
2013-10-03 07:11:26 +00:00
|
|
|
#include "nsIHTMLCollection.h"
|
|
|
|
#include "nsInterfaceHashtable.h"
|
2013-10-03 07:11:27 +00:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsWrapperCache.h"
|
2013-10-03 07:11:26 +00:00
|
|
|
|
|
|
|
class nsGenericHTMLFormElement;
|
|
|
|
class nsIFormControl;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class HTMLFormElement;
|
|
|
|
class HTMLImageElement;
|
2014-07-16 16:44:19 +00:00
|
|
|
class OwningRadioNodeListOrElement;
|
2014-06-17 15:03:42 +00:00
|
|
|
template<typename> struct Nullable;
|
2013-10-03 07:11:26 +00:00
|
|
|
|
2014-11-25 18:56:07 +00:00
|
|
|
class HTMLFormControlsCollection MOZ_FINAL : public nsIHTMLCollection
|
|
|
|
, public nsWrapperCache
|
2013-10-03 07:11:26 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-09-02 00:49:25 +00:00
|
|
|
explicit HTMLFormControlsCollection(HTMLFormElement* aForm);
|
2013-10-03 07:11:26 +00:00
|
|
|
|
|
|
|
void DropFormReference();
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIDOMHTMLCollection interface
|
|
|
|
NS_DECL_NSIDOMHTMLCOLLECTION
|
|
|
|
|
2015-01-06 20:13:36 +00:00
|
|
|
virtual Element* GetElementAt(uint32_t index) MOZ_OVERRIDE;
|
2013-10-03 07:11:26 +00:00
|
|
|
virtual nsINode* GetParentObject() MOZ_OVERRIDE;
|
|
|
|
|
2013-11-11 07:55:41 +00:00
|
|
|
virtual Element*
|
|
|
|
GetFirstNamedElement(const nsAString& aName, bool& aFound) MOZ_OVERRIDE;
|
|
|
|
|
2013-10-03 07:11:27 +00:00
|
|
|
void
|
|
|
|
NamedGetter(const nsAString& aName,
|
|
|
|
bool& aFound,
|
2014-07-16 16:44:19 +00:00
|
|
|
Nullable<OwningRadioNodeListOrElement>& aResult);
|
2013-10-03 07:11:27 +00:00
|
|
|
void
|
|
|
|
NamedItem(const nsAString& aName,
|
2014-07-16 16:44:19 +00:00
|
|
|
Nullable<OwningRadioNodeListOrElement>& aResult)
|
2013-10-03 07:11:27 +00:00
|
|
|
{
|
|
|
|
bool dummy;
|
|
|
|
NamedGetter(aName, dummy, aResult);
|
|
|
|
}
|
2014-04-16 02:58:44 +00:00
|
|
|
virtual void GetSupportedNames(unsigned aFlags,
|
|
|
|
nsTArray<nsString>& aNames) MOZ_OVERRIDE;
|
2013-10-03 07:11:26 +00:00
|
|
|
|
|
|
|
nsresult AddElementToTable(nsGenericHTMLFormElement* aChild,
|
|
|
|
const nsAString& aName);
|
|
|
|
nsresult AddImageElementToTable(HTMLImageElement* aChild,
|
|
|
|
const nsAString& aName);
|
|
|
|
nsresult RemoveElementFromTable(nsGenericHTMLFormElement* aChild,
|
|
|
|
const nsAString& aName);
|
|
|
|
nsresult IndexOfControl(nsIFormControl* aControl,
|
|
|
|
int32_t* aIndex);
|
|
|
|
|
|
|
|
nsISupports* NamedItemInternal(const nsAString& aName, bool aFlushContent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a sorted list of form control elements. This list is sorted
|
|
|
|
* in document order and contains the controls in the mElements and
|
|
|
|
* mNotInElements list. This function does not add references to the
|
|
|
|
* elements.
|
|
|
|
*
|
|
|
|
* @param aControls The list of sorted controls[out].
|
|
|
|
* @return NS_OK or NS_ERROR_OUT_OF_MEMORY.
|
|
|
|
*/
|
|
|
|
nsresult GetSortedControls(nsTArray<nsGenericHTMLFormElement*>& aControls) const;
|
|
|
|
|
|
|
|
// nsWrapperCache
|
2013-11-12 15:22:22 +00:00
|
|
|
using nsWrapperCache::GetWrapperPreserveColor;
|
2014-04-08 22:27:18 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-11-12 15:22:22 +00:00
|
|
|
protected:
|
2014-06-25 02:09:15 +00:00
|
|
|
virtual ~HTMLFormControlsCollection();
|
2013-11-12 15:22:22 +00:00
|
|
|
virtual JSObject* GetWrapperPreserveColorInternal() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return nsWrapperCache::GetWrapperPreserveColor();
|
|
|
|
}
|
|
|
|
public:
|
2013-10-03 07:11:26 +00:00
|
|
|
|
|
|
|
static bool ShouldBeInElements(nsIFormControl* aFormControl);
|
|
|
|
|
|
|
|
HTMLFormElement* mForm; // WEAK - the form owns me
|
|
|
|
|
|
|
|
nsTArray<nsGenericHTMLFormElement*> mElements; // Holds WEAK references - bug 36639
|
|
|
|
|
|
|
|
// This array holds on to all form controls that are not contained
|
|
|
|
// in mElements (form.elements in JS, see ShouldBeInFormControl()).
|
|
|
|
// This is needed to properly clean up the bi-directional references
|
|
|
|
// (both weak and strong) between the form and its form controls.
|
|
|
|
|
|
|
|
nsTArray<nsGenericHTMLFormElement*> mNotInElements; // Holds WEAK references
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(HTMLFormControlsCollection)
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Drop all our references to the form elements
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
// Flush out the content model so it's up to date.
|
|
|
|
void FlushPendingNotifications();
|
|
|
|
|
|
|
|
// A map from an ID or NAME attribute to the form control(s), this
|
|
|
|
// hash holds strong references either to the named form control, or
|
|
|
|
// to a list of named form controls, in the case where this hash
|
|
|
|
// holds on to a list of named form controls the list has weak
|
|
|
|
// references to the form control.
|
|
|
|
|
|
|
|
nsInterfaceHashtable<nsStringHashKey,nsISupports> mNameLookupTable;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_HTMLFormControlsCollection_h
|