Bug 801176 - part1-v8: Modify webidl for 2d canvas. r=smaug, roc

---
 dom/canvas/CanvasRenderingContext2D.cpp    | 38 +++++++++++++++
 dom/canvas/CanvasRenderingContext2D.h      |  6 +++
 dom/webidl/CanvasRenderingContext2D.webidl | 76 ++++++++++++++++++------------
 dom/webidl/HTMLCanvasElement.webidl        |  2 +
 dom/webidl/WebGLRenderingContext.webidl    |  2 +-
 dom/workers/WorkerPrefs.h                  |  1 +
 6 files changed, 95 insertions(+), 30 deletions(-)
This commit is contained in:
vincentliu 2016-03-04 15:22:16 +08:00
Родитель 547da6e1b6
Коммит 2a98ba1c2c
6 изменённых файлов: 95 добавлений и 30 удалений

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

@ -106,6 +106,7 @@
#include "mozilla/dom/SVGMatrix.h"
#include "mozilla/dom/TextMetrics.h"
#include "mozilla/dom/SVGMatrix.h"
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/FloatingPoint.h"
#include "nsGlobalWindow.h"
#include "GLContext.h"
@ -3456,6 +3457,43 @@ CanvasRenderingContext2D::GetHitRegionRect(Element* aElement, nsRect& aRect)
return false;
}
/* static */ bool
CanvasRenderingContext2D::PrefCanvasPathEnabled(JSContext* aCx, JSObject* aObj)
{
if (NS_IsMainThread()) {
return Preferences::GetBool("canvas.path.enabled");
} else {
workers::WorkerPrivate* workerPrivate = workers::GetWorkerPrivateFromContext(aCx);
MOZ_ASSERT(workerPrivate);
return (workerPrivate->CanvasPathEnabled() && workerPrivate->OffscreenCanvasEnabled());
}
}
void
CanvasRenderingContext2D::GetCanvas(Nullable<dom::OwningHTMLCanvasElementOrOffscreenCanvas>& aRetval)
{
if (mCanvasElement) {
MOZ_RELEASE_ASSERT(!mOffscreenCanvas);
if (mCanvasElement->IsInNativeAnonymousSubtree()) {
aRetval.SetNull();
} else {
aRetval.SetValue().SetAsHTMLCanvasElement() = mCanvasElement;
}
} else if (mOffscreenCanvas) {
aRetval.SetValue().SetAsOffscreenCanvas() = mOffscreenCanvas;
} else {
aRetval.SetNull();
}
}
void
CanvasRenderingContext2D::Commit()
{
if (mOffscreenCanvas) {
mOffscreenCanvas->CommitFrameToCompositor();
}
}
/**
* Used for nsBidiPresUtils::ProcessText
*/

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

@ -46,6 +46,7 @@ class OwningStringOrCanvasGradientOrCanvasPattern;
class TextMetrics;
class CanvasFilterChainObserver;
class CanvasPath;
class OwningHTMLCanvasElementOrOffscreenCanvas;
extern const mozilla::gfx::Float SIGMA_MAX;
@ -79,6 +80,10 @@ public:
return mCanvasElement->GetOriginalCanvas();
}
void GetCanvas(Nullable<dom::OwningHTMLCanvasElementOrOffscreenCanvas>& aRetval);
void Commit();
void Save();
void Restore();
void Scale(double aX, double aY, mozilla::ErrorResult& aError);
@ -543,6 +548,7 @@ public:
// return true and fills in the bound rect if element has a hit region.
bool GetHitRegionRect(Element* aElement, nsRect& aRect) override;
static bool PrefCanvasPathEnabled(JSContext* aCx, JSObject* aObj);
protected:
nsresult GetImageDataArray(JSContext* aCx, int32_t aX, int32_t aY,
uint32_t aWidth, uint32_t aHeight,

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

@ -31,11 +31,15 @@ typedef (HTMLImageElement or
HTMLVideoElement or
ImageBitmap) CanvasImageSource;
[Exposed=(Window,Worker),
Func="mozilla::dom::OffscreenCanvas::PrefEnabledOnWorkerThread"]
interface CanvasRenderingContext2D {
// back-reference to the canvas. Might be null if we're not
// associated with a canvas.
readonly attribute HTMLCanvasElement? canvas;
readonly attribute CanvasObj? canvas;
void commit();
// state
void save(); // push state on state stack
@ -61,6 +65,9 @@ interface CanvasRenderingContext2D {
[Throws]
attribute DOMString globalCompositeOperation; // (default source-over)
// drawing images
// NOT IMPLEMENTED attribute boolean imageSmoothingEnabled; // (default true)
// colors and styles (see also the CanvasDrawingStyles interface)
attribute (DOMString or CanvasGradient or CanvasPattern) strokeStyle; // (default black)
attribute (DOMString or CanvasGradient or CanvasPattern) fillStyle; // (default black)
@ -80,9 +87,6 @@ interface CanvasRenderingContext2D {
attribute double shadowBlur; // (default 0)
attribute DOMString shadowColor; // (default transparent black)
[Pref="canvas.filters.enabled", SetterThrows]
attribute DOMString filter; // (default empty string = no filter)
// rects
[LenientFloat]
void clearRect(double x, double y, double w, double h);
@ -97,10 +101,7 @@ interface CanvasRenderingContext2D {
void fill(Path2D path, optional CanvasWindingRule winding = "nonzero");
void stroke();
void stroke(Path2D path);
[Pref="canvas.focusring.enabled", Throws] void drawFocusIfNeeded(Element element);
// NOT IMPLEMENTED void drawSystemFocusRing(Path path, HTMLElement element);
[Pref="canvas.customfocusring.enabled"] boolean drawCustomFocusRing(Element element);
// NOT IMPLEMENTED boolean drawCustomFocusRing(Path path, HTMLElement element);
[Exposed=Window, Pref="canvas.focusring.enabled", Throws] void drawFocusIfNeeded(Element element);
// NOT IMPLEMENTED void scrollPathIntoView();
// NOT IMPLEMENTED void scrollPathIntoView(Path path);
void clip(optional CanvasWindingRule winding = "nonzero");
@ -112,16 +113,13 @@ interface CanvasRenderingContext2D {
boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y);
// text (see also the CanvasDrawingStyles interface)
[Throws, LenientFloat]
[Exposed=Window, Throws, LenientFloat]
void fillText(DOMString text, double x, double y, optional double maxWidth);
[Throws, LenientFloat]
[Exposed=Window, Throws, LenientFloat]
void strokeText(DOMString text, double x, double y, optional double maxWidth);
[NewObject, Throws]
[Exposed=Window, NewObject, Throws]
TextMetrics measureText(DOMString text);
// drawing images
// NOT IMPLEMENTED attribute boolean imageSmoothingEnabled; // (default true)
[Throws, LenientFloat]
void drawImage(CanvasImageSource image, double dx, double dy);
[Throws, LenientFloat]
@ -130,9 +128,9 @@ interface CanvasRenderingContext2D {
void drawImage(CanvasImageSource image, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh);
// hit regions
[Pref="canvas.hitregions.enabled", Throws] void addHitRegion(optional HitRegionOptions options);
[Pref="canvas.hitregions.enabled"] void removeHitRegion(DOMString id);
[Pref="canvas.hitregions.enabled"] void clearHitRegions();
[Exposed=Window, Pref="canvas.hitregions.enabled", Throws] void addHitRegion(optional HitRegionOptions options);
[Exposed=Window, Pref="canvas.hitregions.enabled"] void removeHitRegion(DOMString id);
[Exposed=Window, Pref="canvas.hitregions.enabled"] void clearHitRegions();
// pixel manipulation
[NewObject, Throws]
@ -145,6 +143,27 @@ interface CanvasRenderingContext2D {
void putImageData(ImageData imagedata, double dx, double dy);
[Throws]
void putImageData(ImageData imagedata, double dx, double dy, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight);
};
CanvasRenderingContext2D implements CanvasDrawingStyles;
CanvasRenderingContext2D implements CanvasPathMethods;
[Exposed=(Window,Worker)]
partial interface CanvasRenderingContext2D {
[Throws]
attribute any mozDash; /* default |null| */
[LenientFloat]
attribute double mozDashOffset; /* default 0.0 */
};
[Exposed=Window]
partial interface CanvasRenderingContext2D {
[Pref="canvas.filters.enabled", SetterThrows]
attribute DOMString filter; // (default empty string = no filter)
// NOT IMPLEMENTED void drawSystemFocusRing(Path path, HTMLElement element);
[Pref="canvas.customfocusring.enabled"] boolean drawCustomFocusRing(Element element);
// NOT IMPLEMENTED boolean drawCustomFocusRing(Path path, HTMLElement element);
// Mozilla-specific stuff
// FIXME Bug 768048 mozCurrentTransform/mozCurrentTransformInverse should return a WebIDL array.
@ -155,12 +174,6 @@ interface CanvasRenderingContext2D {
attribute DOMString mozFillRule; /* "evenodd", "nonzero" (default) */
[Throws]
attribute any mozDash; /* default |null| */
[LenientFloat]
attribute double mozDashOffset; /* default 0.0 */
[SetterThrows]
attribute DOMString mozTextStyle;
@ -249,10 +262,8 @@ interface CanvasRenderingContext2D {
[ChromeOnly]
void demote();
};
CanvasRenderingContext2D implements CanvasDrawingStyles;
CanvasRenderingContext2D implements CanvasPathMethods;
[NoInterfaceObject]
[NoInterfaceObject, Exposed=(Window,Worker)]
interface CanvasDrawingStyles {
// line caps/joins
[LenientFloat]
@ -269,13 +280,15 @@ interface CanvasDrawingStyles {
[LenientFloat] attribute double lineDashOffset;
// text
[SetterThrows]
[Exposed=Window, SetterThrows]
attribute DOMString font; // (default 10px sans-serif)
[Exposed=Window]
attribute DOMString textAlign; // "start", "end", "left", "right", "center" (default: "start")
[Exposed=Window]
attribute DOMString textBaseline; // "top", "hanging", "middle", "alphabetic", "ideographic", "bottom" (default: "alphabetic")
};
[NoInterfaceObject]
[NoInterfaceObject, Exposed=(Window,Worker)]
interface CanvasPathMethods {
// shared path API methods
void closePath();
@ -301,6 +314,8 @@ interface CanvasPathMethods {
// NOT IMPLEMENTED [LenientFloat] void ellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle, double endAngle, boolean anticlockwise);
};
[Exposed=(Window,Worker),
Func="mozilla::dom::OffscreenCanvas::PrefEnabledOnWorkerThread"]
interface CanvasGradient {
// opaque object
[Throws]
@ -308,6 +323,8 @@ interface CanvasGradient {
void addColorStop(float offset, DOMString color);
};
[Exposed=(Window,Worker),
Func="mozilla::dom::OffscreenCanvas::PrefEnabledOnWorkerThread"]
interface CanvasPattern {
// opaque object
// [Throws, LenientFloat] - could not do this overload because of bug 1020975
@ -342,7 +359,8 @@ interface TextMetrics {
};
[Pref="canvas.path.enabled",
[Exposed=(Window,Worker),
Func="CanvasRenderingContext2D::PrefCanvasPathEnabled",
Constructor,
Constructor(Path2D other),
Constructor(DOMString pathString)]

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

@ -63,6 +63,8 @@ interface MozCanvasPrintState
void done();
};
typedef (HTMLCanvasElement or OffscreenCanvas) CanvasObj;
callback PrintCallback = void(MozCanvasPrintState ctx);
callback FileCallback = void(Blob file);

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

@ -524,7 +524,7 @@ interface WebGLRenderingContext {
const GLenum BROWSER_DEFAULT_WEBGL = 0x9244;
// The canvas might actually be null in some cases, apparently.
readonly attribute (HTMLCanvasElement or OffscreenCanvas)? canvas;
readonly attribute CanvasObj? canvas;
readonly attribute GLsizei drawingBufferWidth;
readonly attribute GLsizei drawingBufferHeight;

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

@ -36,6 +36,7 @@ WORKER_SIMPLE_PREF("dom.push.enabled", PushEnabled, PUSH_ENABLED)
WORKER_SIMPLE_PREF("dom.requestcache.enabled", RequestCacheEnabled, REQUESTCACHE_ENABLED)
WORKER_SIMPLE_PREF("dom.requestcontext.enabled", RequestContextEnabled, REQUESTCONTEXT_ENABLED)
WORKER_SIMPLE_PREF("gfx.offscreencanvas.enabled", OffscreenCanvasEnabled, OFFSCREENCANVAS_ENABLED)
WORKER_SIMPLE_PREF("canvas.path.enabled", CanvasPathEnabled, CANVASPATH_ENABLED)
WORKER_PREF("dom.workers.latestJSVersion", JSVersionChanged)
WORKER_PREF("intl.accept_languages", PrefLanguagesChanged)
WORKER_PREF("general.appname.override", AppNameOverrideChanged)