Bug 801712 part 2. Switch ImageData to WebIDL bindings. r=peterv

This commit is contained in:
Boris Zbarsky 2012-10-22 13:08:52 -04:00
Родитель 7a7136cc71
Коммит b598ec354c
15 изменённых файлов: 73 добавлений и 137 удалений

Просмотреть файл

@ -4193,7 +4193,7 @@ NS_IMETHODIMP
CanvasRenderingContext2D::GetImageData(double aSx, double aSy,
double aSw, double aSh,
JSContext* aCx,
nsIDOMImageData** aRetval)
nsISupports** aRetval)
{
ErrorResult rv;
*aRetval = GetImageData(aCx, aSx, aSy, aSw, aSh, rv).get();
@ -4336,7 +4336,7 @@ CanvasRenderingContext2D::FillRuleChanged()
void
CanvasRenderingContext2D::PutImageData(JSContext* cx,
ImageData* imageData, double dx,
ImageData& imageData, double dx,
double dy, ErrorResult& error)
{
if (!FloatValidate(dx, dy)) {
@ -4344,16 +4344,16 @@ CanvasRenderingContext2D::PutImageData(JSContext* cx,
return;
}
dom::Uint8ClampedArray arr(cx, imageData->GetDataObject());
dom::Uint8ClampedArray arr(cx, imageData.GetDataObject());
error = PutImageData_explicit(JS_DoubleToInt32(dx), JS_DoubleToInt32(dy),
imageData->Width(), imageData->Height(),
imageData.Width(), imageData.Height(),
arr.Data(), arr.Length(), false, 0, 0, 0, 0);
}
void
CanvasRenderingContext2D::PutImageData(JSContext* cx,
ImageData* imageData, double dx,
ImageData& imageData, double dx,
double dy, double dirtyX,
double dirtyY, double dirtyWidth,
double dirtyHeight,
@ -4364,10 +4364,10 @@ CanvasRenderingContext2D::PutImageData(JSContext* cx,
return;
}
dom::Uint8ClampedArray arr(cx, imageData->GetDataObject());
dom::Uint8ClampedArray arr(cx, imageData.GetDataObject());
error = PutImageData_explicit(JS_DoubleToInt32(dx), JS_DoubleToInt32(dy),
imageData->Width(), imageData->Height(),
imageData.Width(), imageData.Height(),
arr.Data(), arr.Length(), true,
JS_DoubleToInt32(dirtyX),
JS_DoubleToInt32(dirtyY),
@ -4575,11 +4575,11 @@ CanvasRenderingContext2D::CreateImageData(JSContext* cx, double sw,
already_AddRefed<ImageData>
CanvasRenderingContext2D::CreateImageData(JSContext* cx,
ImageData* imagedata,
ImageData& imagedata,
ErrorResult& error)
{
return mozilla::dom::CreateImageData(cx, this, imagedata->Width(),
imagedata->Height(), error);
return mozilla::dom::CreateImageData(cx, this, imagedata.Width(),
imagedata.Height(), error);
}
NS_IMETHODIMP
@ -4587,7 +4587,7 @@ CanvasRenderingContext2D::CreateImageData(const JS::Value &arg1,
const JS::Value &arg2,
JSContext* cx,
uint8_t optional_argc,
nsIDOMImageData** retval)
nsISupports** retval)
{
/* Should never be called; handled entirely in new bindings */
return NS_ERROR_NOT_IMPLEMENTED;

Просмотреть файл

@ -289,14 +289,14 @@ public:
CreateImageData(JSContext* cx, double sw, double sh,
mozilla::ErrorResult& error);
already_AddRefed<mozilla::dom::ImageData>
CreateImageData(JSContext* cx, mozilla::dom::ImageData* imagedata,
CreateImageData(JSContext* cx, mozilla::dom::ImageData& imagedata,
mozilla::ErrorResult& error);
already_AddRefed<mozilla::dom::ImageData>
GetImageData(JSContext* cx, double sx, double sy, double sw, double sh,
mozilla::ErrorResult& error);
void PutImageData(JSContext* cx, mozilla::dom::ImageData* imageData,
void PutImageData(JSContext* cx, mozilla::dom::ImageData& imageData,
double dx, double dy, mozilla::ErrorResult& error);
void PutImageData(JSContext* cx, mozilla::dom::ImageData* imageData,
void PutImageData(JSContext* cx, mozilla::dom::ImageData& imageData,
double dx, double dy, double dirtyX, double dirtyY,
double dirtyWidth, double dirtyHeight,
mozilla::ErrorResult& error);

Просмотреть файл

@ -8,12 +8,10 @@
#include "nsDOMClassInfoID.h"
#include "nsContentUtils.h"
#include "mozilla/dom/CanvasRenderingContext2DBinding.h"
#include "mozilla/dom/ImageDataBinding.h"
#include "jsapi.h"
DOMCI_DATA(ImageData, mozilla::dom::ImageData)
namespace mozilla {
namespace dom {
@ -21,9 +19,7 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(ImageData)
NS_IMPL_CYCLE_COLLECTING_RELEASE(ImageData)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ImageData)
NS_INTERFACE_MAP_ENTRY(nsIDOMImageData)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(ImageData)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION_CLASS(ImageData)
@ -40,30 +36,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ImageData)
tmp->DropData();
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
/* readonly attribute unsigned long width; */
NS_IMETHODIMP
ImageData::GetWidth(uint32_t* aWidth)
{
*aWidth = Width();
return NS_OK;
}
/* readonly attribute unsigned long height; */
NS_IMETHODIMP
ImageData::GetHeight(uint32_t* aHeight)
{
*aHeight = Height();
return NS_OK;
}
/* readonly attribute jsval data; */
NS_IMETHODIMP
ImageData::GetData(JSContext* aCx, JS::Value* aData)
{
*aData = JS::ObjectOrNullValue(GetDataObject());
return JS_WrapValue(aCx, aData) ? NS_OK : NS_ERROR_FAILURE;
}
void
ImageData::HoldData()
{
@ -79,5 +51,11 @@ ImageData::DropData()
}
}
JSObject*
ImageData::WrapObject(JSContext* cx, JSObject* scope)
{
return ImageDataBinding::Wrap(cx, scope, this);
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -21,7 +21,7 @@
namespace mozilla {
namespace dom {
class ImageData MOZ_FINAL : public nsIDOMImageData
class ImageData MOZ_FINAL : public nsISupports
{
public:
ImageData(uint32_t aWidth, uint32_t aHeight, JSObject& aData)
@ -40,7 +40,6 @@ public:
}
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIDOMIMAGEDATA
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ImageData)
uint32_t Width() const
@ -61,6 +60,8 @@ public:
return mData;
}
JSObject* WrapObject(JSContext* cx, JSObject* scope);
private:
void HoldData();
void DropData();

Просмотреть файл

@ -539,6 +539,8 @@ using mozilla::dom::indexedDB::IDBWrapperCache;
#include "nsIOpenWindowEventDetail.h"
#include "nsIDOMGlobalObjectConstructor.h"
#include "nsIDOMCanvasRenderingContext2D.h"
#include "DOMFileHandle.h"
#include "FileRequest.h"
#include "LockedFile.h"
@ -1340,8 +1342,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(TextMetrics, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(ImageData, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozCanvasPrintState, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
@ -3869,10 +3869,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMTextMetrics)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(ImageData, nsIDOMImageData)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMImageData)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(MozCanvasPrintState, nsIDOMMozCanvasPrintState)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozCanvasPrintState)
DOM_CLASSINFO_MAP_END

Просмотреть файл

@ -319,7 +319,6 @@ DOMCI_CLASS(HTMLCanvasElement)
DOMCI_CLASS(CanvasGradient)
DOMCI_CLASS(CanvasPattern)
DOMCI_CLASS(TextMetrics)
DOMCI_CLASS(ImageData)
DOMCI_CLASS(MozCanvasPrintState)
// SmartCard Events

Просмотреть файл

@ -55,8 +55,7 @@ DOMCI_CASTABLE_INTERFACE(nsGenericHTMLElement, nsGenericHTMLElement, 6, \
_extra) \
DOMCI_CASTABLE_INTERFACE(nsHTMLDocument, nsIDocument, 7, _extra) \
DOMCI_CASTABLE_INTERFACE(nsStyledElement, nsStyledElement, 8, _extra) \
DOMCI_CASTABLE_INTERFACE(nsSVGStylableElement, nsIContent, 9, _extra) \
DOMCI_CASTABLE_INTERFACE(nsIDOMImageData, nsIDOMImageData, 12, _extra)
DOMCI_CASTABLE_INTERFACE(nsSVGStylableElement, nsIContent, 9, _extra)
// Make sure all classes mentioned in DOMCI_CASTABLE_INTERFACES
// have been declared.

Просмотреть файл

@ -56,6 +56,7 @@
#include "nsScriptNameSpaceManager.h"
#include "StructuredCloneTags.h"
#include "mozilla/dom/ImageData.h"
#include "mozilla/dom/ImageDataBinding.h"
#include "nsJSPrincipals.h"
#include "jsdbgapi.h"
@ -3778,22 +3779,14 @@ NS_DOMReadStructuredClone(JSContext* cx,
MOZ_ASSERT(dataArray.isObject());
// Construct the ImageData.
nsCOMPtr<nsIDOMImageData> imageData = new ImageData(width, height,
dataArray.toObject());
nsRefPtr<ImageData> imageData = new ImageData(width, height,
dataArray.toObject());
// Wrap it in a jsval.
JSObject* global = JS_GetGlobalForScopeChain(cx);
if (!global) {
return nullptr;
}
nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
JS::Value val;
nsresult rv =
nsContentUtils::WrapNative(cx, global, imageData, &val,
getter_AddRefs(wrapper));
if (NS_FAILED(rv)) {
return nullptr;
}
return val.toObjectOrNull();
return imageData->WrapObject(cx, global);
}
// Don't know what this is. Bail.
@ -3807,32 +3800,23 @@ NS_DOMWriteStructuredClone(JSContext* cx,
JSObject* obj,
void *closure)
{
nsCOMPtr<nsIXPConnectWrappedNative> wrappedNative;
nsContentUtils::XPConnect()->
GetWrappedNativeOfJSObject(cx, obj, getter_AddRefs(wrappedNative));
nsISupports *native = wrappedNative ? wrappedNative->Native() : nullptr;
nsCOMPtr<nsIDOMImageData> imageData = do_QueryInterface(native);
if (imageData) {
// Prepare the ImageData internals.
uint32_t width, height;
JS::Value dataArray;
if (NS_FAILED(imageData->GetWidth(&width)) ||
NS_FAILED(imageData->GetHeight(&height)) ||
NS_FAILED(imageData->GetData(cx, &dataArray)))
{
return false;
}
// Write the internals to the stream.
return JS_WriteUint32Pair(writer, SCTAG_DOM_IMAGEDATA, 0) &&
JS_WriteUint32Pair(writer, width, height) &&
JS_WriteTypedArray(writer, dataArray);
ImageData* imageData;
nsresult rv = UnwrapObject<ImageData>(cx, obj, imageData);
if (NS_FAILED(rv)) {
// Don't know what this is. Bail.
xpc::Throw(cx, NS_ERROR_DOM_DATA_CLONE_ERR);
return JS_FALSE;
}
// Don't know what this is. Bail.
xpc::Throw(cx, NS_ERROR_DOM_DATA_CLONE_ERR);
return JS_FALSE;
// Prepare the ImageData internals.
uint32_t width = imageData->Width();
uint32_t height = imageData->Height();
JS::Value dataArray = JS::ObjectValue(*imageData->GetDataObject());
// Write the internals to the stream.
return JS_WriteUint32Pair(writer, SCTAG_DOM_IMAGEDATA, 0) &&
JS_WriteUint32Pair(writer, width, height) &&
JS_WriteTypedArray(writer, dataArray);
}
void

Просмотреть файл

@ -229,6 +229,10 @@ DOMInterfaces = {
'workers': True,
}],
'ImageData': {
'wrapperCache': False
},
'InputStream': [
{
'nativeType': 'nsIInputStream',
@ -628,7 +632,6 @@ addExternalIface('Element', nativeType='nsGenericElement')
addExternalIface('File')
addExternalIface('HitRegionOptions', nativeType='nsISupports')
addExternalIface('HTMLElement')
addExternalIface('ImageData', nativeType='mozilla::dom::ImageData')
addExternalIface('MediaStream')
addExternalIface('Node', nativeType='nsINode')
addExternalIface('PaintRequest')

Просмотреть файл

@ -30,14 +30,6 @@ interface nsIDOMTextMetrics : nsISupports
readonly attribute float width;
};
[scriptable, builtinclass, uuid(1ea11207-b3e3-4ffc-a256-bf5c7011e806)]
interface nsIDOMImageData : nsISupports
{
readonly attribute unsigned long width;
readonly attribute unsigned long height;
[implicit_jscontext] readonly attribute jsval data;
};
[scriptable, uuid(c835c768-2dcc-461c-82f5-3653710d2942)]
interface nsIDOMCanvasRenderingContext2D : nsISupports
{
@ -180,8 +172,9 @@ enum CanvasMultiGetterType {
// void putImageData (in ImageData d, in float x, in float y);
// ImageData = { width: #, height: #, data: [r, g, b, a, ...] }
// nsISupports is OK, because the binding code will deal correctly
[implicit_jscontext]
nsIDOMImageData getImageData(in double sx, in double sy, in double sw, in double sh);
nsISupports getImageData(in double sx, in double sy, in double sw, in double sh);
// void putImageData(ImageData imagedata, double dx, double dy);
@ -200,8 +193,9 @@ enum CanvasMultiGetterType {
// ImageData createImageData(double w, double h);
// ImageData createImageData(ImageData data);
// nsISupports is OK, because the binding code will deal correctly
[implicit_jscontext, optional_argc]
nsIDOMImageData createImageData(in jsval arg1, [optional] in jsval arg2);
nsISupports createImageData(in jsval arg1, [optional] in jsval arg2);
// image smoothing mode -- if disabled, images won't be smoothed
// if scaled.

Просмотреть файл

@ -17,7 +17,6 @@ interface HitRegionOptions;
interface HTMLCanvasElement;
interface HTMLImageElement;
interface HTMLVideoElement;
interface ImageData;
interface TextMetrics;
interface Window;
interface XULElement;

Просмотреть файл

@ -0,0 +1,17 @@
/* -*- Mode: IDL; 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/.
*
* The origin of this IDL file is
* http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#imagedata
*
* © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and Opera Software ASA.
* You are granted a license to use, reproduce and create derivative works of this document.
*/
interface ImageData {
readonly attribute unsigned long width;
readonly attribute unsigned long height;
readonly attribute Uint8ClampedArray data;
};

Просмотреть файл

@ -31,6 +31,7 @@ webidl_files = \
HTMLCollection.webidl \
HTMLOptionsCollection.webidl \
HTMLPropertiesCollection.webidl \
ImageData.webidl \
NodeList.webidl \
PaintRequestList.webidl \
Performance.webidl \

Просмотреть файл

@ -61,7 +61,6 @@ members = [
'nsIDOMTextMetrics.*',
'nsIDOMCanvasGradient.*',
'nsIDOMCanvasPattern.*',
'nsIDOMImageData.*',
# dom/interfaces/core
'nsIDOMCharacterData.data',
@ -457,7 +456,6 @@ irregularFilenames = {
'nsIDOMTextMetrics': 'nsIDOMCanvasRenderingContext2D',
'nsIDOMCanvasGradient': 'nsIDOMCanvasRenderingContext2D',
'nsIDOMCanvasPattern': 'nsIDOMCanvasRenderingContext2D',
'nsIDOMImageData': 'nsIDOMCanvasRenderingContext2D',
'nsIDOMBlob': 'nsIDOMFile',
@ -484,14 +482,12 @@ customIncludes = [
'nsSVGStylableElement.h',
'nsHTMLDocument.h',
'nsDOMQS.h',
'nsDOMStringMap.h',
'mozilla/dom/ImageData.h'
'nsDOMStringMap.h'
]
customReturnInterfaces = [
'nsIDOMCanvasPattern',
'nsIDOMCanvasGradient',
'nsIDOMImageData'
]
nsIDOMNode_GetChildNodes_customMethodCallCode = """
@ -997,18 +993,5 @@ customMethodCalls = {
'nsIDOMWindow_SetOnmouseleave' : {
'thisType' : 'nsIDOMWindow',
'unwrapThisFailureFatal' : False
},
'nsIDOMImageData_GetWidth': {
'thisType': 'nsIDOMImageData',
'code': 'uint32_t result = static_cast<mozilla::dom::ImageData*>(self)->Width();',
'canFail': False
},
'nsIDOMImageData_GetHeight': {
'thisType': 'nsIDOMImageData',
'code': 'uint32_t result = static_cast<mozilla::dom::ImageData*>(self)->Height();',
'canFail': False
},
'nsIDOMImageData_GetData': {
'canFail': False
}
}

Просмотреть файл

@ -5,7 +5,6 @@
#ifndef nsDOMQS_h__
#define nsDOMQS_h__
#include "mozilla/dom/ImageData.h"
#include "nsDOMClassInfoID.h"
#include "nsGenericHTMLElement.h"
#include "nsHTMLCanvasElement.h"
@ -183,23 +182,6 @@ DEFINE_UNWRAP_CAST_HTML(optgroup, nsHTMLOptGroupElement)
DEFINE_UNWRAP_CAST_HTML(option, nsHTMLOptionElement)
DEFINE_UNWRAP_CAST_HTML(video, nsHTMLVideoElement)
template <>
inline nsresult
xpc_qsUnwrapArg<mozilla::dom::ImageData>(JSContext *cx, jsval v,
mozilla::dom::ImageData **ppArg,
mozilla::dom::ImageData **ppArgRef,
jsval *vp)
{
nsIDOMImageData* arg;
nsIDOMImageData* argRef;
nsresult rv = xpc_qsUnwrapArg<nsIDOMImageData>(cx, v, &arg, &argRef, vp);
if (NS_SUCCEEDED(rv)) {
*ppArg = static_cast<mozilla::dom::ImageData*>(arg);
*ppArgRef = static_cast<mozilla::dom::ImageData*>(argRef);
}
return rv;
}
inline nsISupports*
ToSupports(nsContentList *p)
{