Bug 854090 - Move nsHTMLFormElementSH::FindNamedItem to nsHTMLFormElement; r=khuey

This commit is contained in:
Ms2ger 2013-04-04 09:03:12 +02:00
parent e38aa0d743
commit 0d51d547b4
5 changed files with 38 additions and 56 deletions

View File

@ -20,8 +20,8 @@ class nsIURI;
// IID for the nsIForm interface
#define NS_IFORM_IID \
{ 0x27f1ff6c, 0xeb78, 0x405b, \
{ 0xa6, 0xeb, 0xf0, 0xce, 0xa8, 0x30, 0x85, 0x58 } }
{ 0x5e8464c8, 0x015d, 0x4cf9, \
{ 0x92, 0xc9, 0xa6, 0xb3, 0x30, 0x8f, 0x60, 0x9d } }
/**
* This interface provides some methods that can be used to access the
@ -50,17 +50,6 @@ public:
*/
NS_IMETHOD_(uint32_t) GetElementCount() const = 0;
/**
* Resolve a name in the scope of the form object, this means find
* form controls in this form with the correct value in the name
* attribute.
*
* @param aElement the element to remove
* @param aName the name or id of the element to remove
* @return NS_OK if the element was successfully removed.
*/
NS_IMETHOD_(already_AddRefed<nsISupports>) ResolveName(const nsAString& aName) = 0;
/**
* Get the index of the given control within form.elements.
* @param aControl the control to find the index of

View File

@ -1364,10 +1364,24 @@ nsHTMLFormElement::RemoveElementFromTable(nsGenericHTMLFormElement* aElement,
return mControls->RemoveElementFromTable(aElement, aName);
}
NS_IMETHODIMP_(already_AddRefed<nsISupports>)
nsHTMLFormElement::ResolveName(const nsAString& aName)
already_AddRefed<nsISupports>
nsHTMLFormElement::FindNamedItem(const nsAString& aName,
nsWrapperCache** aCache)
{
return DoResolveName(aName, true);
nsCOMPtr<nsISupports> result = DoResolveName(aName, true);
if (result) {
// FIXME Get the wrapper cache from DoResolveName.
*aCache = nullptr;
return result.forget();
}
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(GetCurrentDoc());
if (!htmlDoc) {
*aCache = nullptr;
return nullptr;
}
return htmlDoc->ResolveName(aName, this, aCache);
}
already_AddRefed<nsISupports>
@ -1933,7 +1947,7 @@ nsHTMLFormElement::GetNextRadioButton(const nsAString& aName,
mSelectedRadioButtons.Get(aName, getter_AddRefs(currentRadio));
}
nsCOMPtr<nsISupports> itemWithName = ResolveName(aName);
nsCOMPtr<nsISupports> itemWithName = DoResolveName(aName, true);
nsCOMPtr<nsINodeList> radioGroup(do_QueryInterface(itemWithName));
if (!radioGroup) {

View File

@ -57,7 +57,6 @@ public:
// nsIForm
NS_IMETHOD_(nsIFormControl*) GetElementAt(int32_t aIndex) const;
NS_IMETHOD_(uint32_t) GetElementCount() const;
NS_IMETHOD_(already_AddRefed<nsISupports>) ResolveName(const nsAString& aName);
NS_IMETHOD_(int32_t) IndexOfControl(nsIFormControl* aControl);
NS_IMETHOD_(nsIFormControl*) GetDefaultSubmitElement() const;
@ -240,6 +239,13 @@ public:
*/
bool HasEverTriedInvalidSubmit() const { return mEverTriedInvalidSubmit; }
/**
* Implements form[name]. Returns form controls in this form with the correct
* value of the name attribute.
*/
already_AddRefed<nsISupports>
FindNamedItem(const nsAString& aName, nsWrapperCache** aCache);
protected:
void PostPasswordEvent();
void EventHandled() { mFormPasswordEvent = nullptr; }
@ -325,7 +331,8 @@ protected:
bool aEarlyNotify);
/**
* Just like ResolveName(), but takes an arg for whether to flush
* Find form controls in this form with the correct value in the name
* attribute.
*/
already_AddRefed<nsISupports> DoResolveName(const nsAString& aName, bool aFlushContent);

View File

@ -7171,32 +7171,6 @@ nsHTMLDocumentSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
// HTMLFormElement helper
// static
nsresult
nsHTMLFormElementSH::FindNamedItem(nsIForm *aForm, jsid id,
nsISupports **aResult,
nsWrapperCache **aCache)
{
nsDependentJSString name(id);
*aResult = aForm->ResolveName(name).get();
// FIXME Get the wrapper cache from nsIForm::ResolveName
*aCache = nullptr;
if (!*aResult) {
nsCOMPtr<nsIContent> content(do_QueryInterface(aForm));
nsCOMPtr<nsIHTMLDocument> html_doc =
do_QueryInterface(content->GetDocument());
if (html_doc && content) {
*aResult = html_doc->ResolveName(name, content, aCache).get();
}
}
return NS_OK;
}
NS_IMETHODIMP
nsHTMLFormElementSH::NewResolve(nsIXPConnectWrappedNative *wrapper,
JSContext *cx, JSObject *obj, jsid id,
@ -7208,10 +7182,11 @@ nsHTMLFormElementSH::NewResolve(nsIXPConnectWrappedNative *wrapper,
(!ObjectIsNativeWrapper(cx, obj) ||
xpc::WrapperFactory::XrayWrapperNotShadowing(obj, id))) {
nsCOMPtr<nsIForm> form(do_QueryWrappedNative(wrapper, obj));
nsCOMPtr<nsISupports> result;
nsWrapperCache *cache;
FindNamedItem(form, id, getter_AddRefs(result), &cache);
nsDependentJSString name(id);
nsWrapperCache* cache;
nsCOMPtr<nsISupports> result =
static_cast<nsHTMLFormElement*>(form.get())->FindNamedItem(name, &cache);
if (result) {
JSAutoRequest ar(cx);
@ -7237,10 +7212,10 @@ nsHTMLFormElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
if (JSID_IS_STRING(id)) {
// For native wrappers, do not get random names on form
nsCOMPtr<nsISupports> result;
nsDependentJSString name(id);
nsWrapperCache* cache;
FindNamedItem(form, id, getter_AddRefs(result), &cache);
nsCOMPtr<nsISupports> result =
static_cast<nsHTMLFormElement*>(form.get())->FindNamedItem(name, &cache);
if (result) {
// Wrap result, result can be either an element or a list of

View File

@ -713,9 +713,6 @@ protected:
{
}
static nsresult FindNamedItem(nsIForm *aForm, jsid id,
nsISupports **aResult, nsWrapperCache **aCache);
public:
NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, uint32_t flags,