зеркало из https://github.com/mozilla/pjs.git
Fix for bug 564585 (Use WrapNativeParent if we can in nsNodeSH::PreCreate). r=bz.
This commit is contained in:
Родитель
9a645465df
Коммит
287b6fd48a
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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___ */
|
|
@ -477,6 +477,7 @@
|
|||
#include "nsIFrameMessageManager.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "nsHTMLSelectElement.h"
|
||||
#include "nsHTMLLegendElement.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
|
||||
|
@ -7391,9 +7392,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.
|
||||
|
@ -7423,15 +7423,14 @@ nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj,
|
|||
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;
|
||||
|
@ -7444,19 +7443,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
|
||||
|
@ -7464,22 +7471,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
|
||||
|
|
Загрузка…
Ссылка в новой задаче