mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Fix for bug 825628 (Implement NamedConstructor) - use NamedConstructor for Image() and Option(). r=bz.
--HG-- extra : rebase_source : f48e0ded2374d84b89d585309309b1a42a95d868
This commit is contained in:
parent
b17c86c836
commit
0de65d896a
@ -91,9 +91,8 @@ NS_IMPL_RELEASE_INHERITED(HTMLImageElement, Element)
|
||||
|
||||
// QueryInterface implementation for HTMLImageElement
|
||||
NS_INTERFACE_TABLE_HEAD(HTMLImageElement)
|
||||
NS_HTML_CONTENT_INTERFACE_TABLE5(HTMLImageElement,
|
||||
NS_HTML_CONTENT_INTERFACE_TABLE4(HTMLImageElement,
|
||||
nsIDOMHTMLImageElement,
|
||||
nsIJSNativeInitializer,
|
||||
nsIImageLoadingContent,
|
||||
imgIOnloadBlocker,
|
||||
imgINotificationObserver)
|
||||
@ -460,33 +459,45 @@ HTMLImageElement::IntrinsicState() const
|
||||
nsImageLoadingContent::ImageState();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HTMLImageElement::Initialize(nsISupports* aOwner, JSContext* aContext,
|
||||
JSObject *aObj, uint32_t argc, jsval *argv)
|
||||
// static
|
||||
already_AddRefed<HTMLImageElement>
|
||||
HTMLImageElement::Image(const GlobalObject& aGlobal,
|
||||
const Optional<uint32_t>& aWidth,
|
||||
const Optional<uint32_t>& aHeight, ErrorResult& aError)
|
||||
{
|
||||
if (argc <= 0) {
|
||||
// Nothing to do here if we don't get any arguments.
|
||||
|
||||
return NS_OK;
|
||||
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aGlobal.Get());
|
||||
nsIDocument* doc;
|
||||
if (!win || !(doc = win->GetExtantDoc())) {
|
||||
aError.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// The first (optional) argument is the width of the image
|
||||
uint32_t width;
|
||||
JSBool ret = JS_ValueToECMAUint32(aContext, argv[0], &width);
|
||||
NS_ENSURE_TRUE(ret, NS_ERROR_INVALID_ARG);
|
||||
|
||||
nsresult rv = SetIntAttr(nsGkAtoms::width, static_cast<int32_t>(width));
|
||||
|
||||
if (NS_SUCCEEDED(rv) && (argc > 1)) {
|
||||
// The second (optional) argument is the height of the image
|
||||
uint32_t height;
|
||||
ret = JS_ValueToECMAUint32(aContext, argv[1], &height);
|
||||
NS_ENSURE_TRUE(ret, NS_ERROR_INVALID_ARG);
|
||||
|
||||
rv = SetIntAttr(nsGkAtoms::height, static_cast<int32_t>(height));
|
||||
nsCOMPtr<nsINodeInfo> nodeInfo =
|
||||
doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::img, nullptr,
|
||||
kNameSpaceID_XHTML,
|
||||
nsIDOMNode::ELEMENT_NODE);
|
||||
if (!nodeInfo) {
|
||||
aError.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return rv;
|
||||
nsRefPtr<HTMLImageElement> img = new HTMLImageElement(nodeInfo.forget());
|
||||
|
||||
if (aWidth.WasPassed()) {
|
||||
img->SetHTMLUnsignedIntAttr(nsGkAtoms::width, aWidth.Value(), aError);
|
||||
if (aError.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (aHeight.WasPassed()) {
|
||||
img->SetHTMLUnsignedIntAttr(nsGkAtoms::height, aHeight.Value(), aError);
|
||||
if (aError.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return img.forget();
|
||||
}
|
||||
|
||||
uint32_t
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsImageLoadingContent.h"
|
||||
#include "nsIDOMHTMLImageElement.h"
|
||||
#include "nsIJSNativeInitializer.h"
|
||||
#include "imgRequestProxy.h"
|
||||
|
||||
namespace mozilla {
|
||||
@ -17,13 +16,16 @@ namespace dom {
|
||||
|
||||
class HTMLImageElement MOZ_FINAL : public nsGenericHTMLElement,
|
||||
public nsImageLoadingContent,
|
||||
public nsIDOMHTMLImageElement,
|
||||
public nsIJSNativeInitializer
|
||||
public nsIDOMHTMLImageElement
|
||||
{
|
||||
public:
|
||||
explicit HTMLImageElement(already_AddRefed<nsINodeInfo> aNodeInfo);
|
||||
virtual ~HTMLImageElement();
|
||||
|
||||
static already_AddRefed<HTMLImageElement>
|
||||
Image(const GlobalObject& aGlobal, const Optional<uint32_t>& aWidth,
|
||||
const Optional<uint32_t>& aHeight, ErrorResult& aError);
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
@ -44,10 +46,6 @@ public:
|
||||
// override from nsImageLoadingContent
|
||||
CORSMode GetCORSMode();
|
||||
|
||||
// nsIJSNativeInitializer
|
||||
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aContext,
|
||||
JSObject* aObj, uint32_t argc, jsval* argv);
|
||||
|
||||
// nsIContent
|
||||
virtual bool ParseAttribute(int32_t aNamespaceID,
|
||||
nsIAtom* aAttribute,
|
||||
|
@ -86,9 +86,8 @@ NS_IMPL_RELEASE_INHERITED(HTMLOptionElement, Element)
|
||||
|
||||
// QueryInterface implementation for HTMLOptionElement
|
||||
NS_INTERFACE_TABLE_HEAD(HTMLOptionElement)
|
||||
NS_HTML_CONTENT_INTERFACE_TABLE2(HTMLOptionElement,
|
||||
nsIDOMHTMLOptionElement,
|
||||
nsIJSNativeInitializer)
|
||||
NS_HTML_CONTENT_INTERFACE_TABLE1(HTMLOptionElement,
|
||||
nsIDOMHTMLOptionElement)
|
||||
NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(HTMLOptionElement,
|
||||
nsGenericHTMLElement)
|
||||
NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLOptionElement)
|
||||
@ -365,87 +364,78 @@ HTMLOptionElement::GetSelect()
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HTMLOptionElement::Initialize(nsISupports* aOwner,
|
||||
JSContext* aContext,
|
||||
JSObject *aObj,
|
||||
uint32_t argc,
|
||||
jsval *argv)
|
||||
already_AddRefed<HTMLOptionElement>
|
||||
HTMLOptionElement::Option(const GlobalObject& aGlobal,
|
||||
const Optional<nsAString>& aText,
|
||||
const Optional<nsAString>& aValue,
|
||||
const Optional<bool>& aDefaultSelected,
|
||||
const Optional<bool>& aSelected, ErrorResult& aError)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aGlobal.Get());
|
||||
nsIDocument* doc;
|
||||
if (!win || !(doc = win->GetExtantDoc())) {
|
||||
aError.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (argc > 0) {
|
||||
// The first (optional) parameter is the text of the option
|
||||
JSString* jsstr = JS_ValueToString(aContext, argv[0]);
|
||||
if (!jsstr) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
nsCOMPtr<nsINodeInfo> nodeInfo =
|
||||
doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::option, nullptr,
|
||||
kNameSpaceID_XHTML,
|
||||
nsIDOMNode::ELEMENT_NODE);
|
||||
if (!nodeInfo) {
|
||||
aError.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsRefPtr<HTMLOptionElement> option = new HTMLOptionElement(nodeInfo.forget());
|
||||
|
||||
if (aText.WasPassed()) {
|
||||
// Create a new text node and append it to the option
|
||||
nsCOMPtr<nsIContent> textContent;
|
||||
result = NS_NewTextNode(getter_AddRefs(textContent),
|
||||
mNodeInfo->NodeInfoManager());
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
aError = NS_NewTextNode(getter_AddRefs(textContent),
|
||||
option->NodeInfo()->NodeInfoManager());
|
||||
if (aError.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t length;
|
||||
const jschar *chars = JS_GetStringCharsAndLength(aContext, jsstr, &length);
|
||||
if (!chars) {
|
||||
return NS_ERROR_FAILURE;
|
||||
textContent->SetText(aText.Value(), false);
|
||||
|
||||
aError = option->AppendChildTo(textContent, false);
|
||||
if (aError.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
textContent->SetText(chars, length, false);
|
||||
|
||||
result = AppendChildTo(textContent, false);
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (argc > 1) {
|
||||
// The second (optional) parameter is the value of the option
|
||||
jsstr = JS_ValueToString(aContext, argv[1]);
|
||||
if (!jsstr) {
|
||||
return NS_ERROR_FAILURE;
|
||||
if (aValue.WasPassed()) {
|
||||
// Set the value attribute for this element. We're calling SetAttr
|
||||
// directly because we want to pass aNotify == false.
|
||||
aError = option->SetAttr(kNameSpaceID_None, nsGkAtoms::value,
|
||||
aValue.Value(), false);
|
||||
if (aError.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t length;
|
||||
const jschar *chars = JS_GetStringCharsAndLength(aContext, jsstr, &length);
|
||||
if (!chars) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Set the value attribute for this element
|
||||
nsAutoString value(chars, length);
|
||||
|
||||
result = SetAttr(kNameSpaceID_None, nsGkAtoms::value, value,
|
||||
false);
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (argc > 2) {
|
||||
// The third (optional) parameter is the defaultSelected value
|
||||
JSBool defaultSelected;
|
||||
JS_ValueToBoolean(aContext, argv[2], &defaultSelected);
|
||||
if (defaultSelected) {
|
||||
result = SetAttr(kNameSpaceID_None, nsGkAtoms::selected,
|
||||
EmptyString(), false);
|
||||
NS_ENSURE_SUCCESS(result, result);
|
||||
if (aDefaultSelected.WasPassed()) {
|
||||
if (aDefaultSelected.Value()) {
|
||||
// We're calling SetAttr directly because we want to pass
|
||||
// aNotify == false.
|
||||
aError = option->SetAttr(kNameSpaceID_None, nsGkAtoms::selected,
|
||||
EmptyString(), false);
|
||||
if (aError.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// XXX This is *untested* behavior. Should work though.
|
||||
if (argc > 3) {
|
||||
JSBool selected;
|
||||
JS_ValueToBoolean(aContext, argv[3], &selected);
|
||||
|
||||
return SetSelected(selected);
|
||||
if (aSelected.WasPassed()) {
|
||||
option->SetSelected(aSelected.Value(), aError);
|
||||
if (aError.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return option.forget();
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -18,13 +18,18 @@ namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class HTMLOptionElement : public nsGenericHTMLElement,
|
||||
public nsIDOMHTMLOptionElement,
|
||||
public nsIJSNativeInitializer
|
||||
public nsIDOMHTMLOptionElement
|
||||
{
|
||||
public:
|
||||
HTMLOptionElement(already_AddRefed<nsINodeInfo> aNodeInfo);
|
||||
virtual ~HTMLOptionElement();
|
||||
|
||||
static already_AddRefed<HTMLOptionElement>
|
||||
Option(const GlobalObject& aGlobal, const Optional<nsAString>& aText,
|
||||
const Optional<nsAString>& aValue,
|
||||
const Optional<bool>& aDefaultSelected,
|
||||
const Optional<bool>& aSelected, ErrorResult& aError);
|
||||
|
||||
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLOptionElement, option)
|
||||
|
||||
// nsISupports
|
||||
@ -47,10 +52,6 @@ public:
|
||||
bool Selected() const;
|
||||
bool DefaultSelected() const;
|
||||
|
||||
// nsIJSNativeInitializer
|
||||
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aContext,
|
||||
JSObject* aObj, uint32_t argc, jsval* argv);
|
||||
|
||||
virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
|
||||
int32_t aModType) const;
|
||||
|
||||
|
@ -17,7 +17,7 @@ interface URI;
|
||||
interface MozChannel;
|
||||
interface nsIStreamListener;
|
||||
|
||||
//[NamedConstructor=Image(optional unsigned long width, optional unsigned long height)]
|
||||
[NamedConstructor=Image(optional unsigned long width, optional unsigned long height)]
|
||||
interface HTMLImageElement : HTMLElement {
|
||||
[SetterThrows]
|
||||
attribute DOMString alt;
|
||||
|
@ -11,13 +11,7 @@
|
||||
* and create derivative works of this document.
|
||||
*/
|
||||
|
||||
/* TODO: Bug 842276
|
||||
* [NamedConstructor=Option(),
|
||||
* NamedConstructor=Option(DOMString text),
|
||||
* NamedConstructor=Option(DOMString text, DOMString value),
|
||||
* NamedConstructor=Option(DOMString text, DOMString value, boolean defaultSelected),
|
||||
* NamedConstructor=Option(DOMString text, DOMString value, boolean defaultSelected, boolean selected)]
|
||||
*/
|
||||
[NamedConstructor=Option(optional DOMString text, optional DOMString value, optional boolean defaultSelected, optional boolean selected)]
|
||||
interface HTMLOptionElement : HTMLElement {
|
||||
[SetterThrows]
|
||||
attribute boolean disabled;
|
||||
|
@ -1,37 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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/. */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
var BUGNUMBER = 407019;
|
||||
var summary = 'Do not assert: !JS_IsExceptionPending(cx) - Browser only';
|
||||
var actual = '';
|
||||
var expect = '';
|
||||
|
||||
printBugNumber(BUGNUMBER);
|
||||
printStatus (summary);
|
||||
|
||||
if (typeof window != 'undefined' && typeof window.Option == 'function' && '__proto__' in window.Option)
|
||||
{
|
||||
try
|
||||
{
|
||||
expect = /Illegal operation on WrappedNative prototype object/;
|
||||
window.Option("u", window.Option.__proto__);
|
||||
for (p in document) { }
|
||||
actual = 'No Error';
|
||||
}
|
||||
catch(ex)
|
||||
{
|
||||
actual = ex + '';
|
||||
}
|
||||
reportMatch(expect, actual, summary);
|
||||
}
|
||||
else
|
||||
{
|
||||
expect = actual = 'Test can only run in a Gecko 1.9 browser or later.';
|
||||
print(actual);
|
||||
reportCompare(expect, actual, summary);
|
||||
}
|
||||
|
||||
|
@ -179,12 +179,6 @@ class nsIDocumentLoaderFactory;
|
||||
|
||||
#define PRODUCT_NAME "Gecko"
|
||||
|
||||
#define NS_HTMLIMGELEMENT_CONTRACTID \
|
||||
"@mozilla.org/content/element/html;1?name=img"
|
||||
|
||||
#define NS_HTMLOPTIONELEMENT_CONTRACTID \
|
||||
"@mozilla.org/content/element/html;1?name=option"
|
||||
|
||||
#ifdef MOZ_MEDIA
|
||||
#define NS_HTMLAUDIOELEMENT_CONTRACTID \
|
||||
"@mozilla.org/content/element/html;1?name=audio"
|
||||
@ -1149,8 +1143,8 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
|
||||
{ "@mozilla.org/content/post-content-iterator;1", &kNS_CONTENTITERATOR_CID },
|
||||
{ "@mozilla.org/content/pre-content-iterator;1", &kNS_PRECONTENTITERATOR_CID },
|
||||
{ "@mozilla.org/content/subtree-content-iterator;1", &kNS_SUBTREEITERATOR_CID },
|
||||
{ NS_HTMLIMGELEMENT_CONTRACTID, &kNS_HTMLIMAGEELEMENT_CID },
|
||||
{ NS_HTMLOPTIONELEMENT_CONTRACTID, &kNS_HTMLOPTIONELEMENT_CID },
|
||||
{ "@mozilla.org/content/element/html;1?name=img", &kNS_HTMLIMAGEELEMENT_CID },
|
||||
{ "@mozilla.org/content/element/html;1?name=option", &kNS_HTMLOPTIONELEMENT_CID },
|
||||
#ifdef MOZ_MEDIA
|
||||
{ NS_HTMLAUDIOELEMENT_CONTRACTID, &kNS_HTMLAUDIOELEMENT_CID },
|
||||
#endif
|
||||
@ -1269,10 +1263,6 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
|
||||
|
||||
static const mozilla::Module::CategoryEntry kLayoutCategories[] = {
|
||||
XPCONNECT_CATEGORIES
|
||||
{ JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY, "Image", NS_HTMLIMGELEMENT_CONTRACTID },
|
||||
{ JAVASCRIPT_GLOBAL_CONSTRUCTOR_PROTO_ALIAS_CATEGORY, "Image", "HTMLImageElement" },
|
||||
{ JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY, "Option", NS_HTMLOPTIONELEMENT_CONTRACTID },
|
||||
{ JAVASCRIPT_GLOBAL_CONSTRUCTOR_PROTO_ALIAS_CATEGORY, "Option", "HTMLOptionElement" },
|
||||
#ifdef MOZ_MEDIA
|
||||
{ JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY, "Audio", NS_HTMLAUDIOELEMENT_CONTRACTID },
|
||||
{ JAVASCRIPT_GLOBAL_CONSTRUCTOR_PROTO_ALIAS_CATEGORY, "Audio", "HTMLAudioElement" },
|
||||
|
Loading…
Reference in New Issue
Block a user