mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
b=279306, update canvas API to reflect latest standard spec; r=stuart,sr=shaver
This commit is contained in:
parent
a8ef008033
commit
c6e2ea87cf
@ -179,6 +179,7 @@ MOZ_SVG_RENDERER_GDIPLUS = @MOZ_SVG_RENDERER_GDIPLUS@
|
||||
MOZ_SVG_RENDERER_LIBART = @MOZ_SVG_RENDERER_LIBART@
|
||||
MOZ_SVG_RENDERER_CAIRO = @MOZ_SVG_RENDERER_CAIRO@
|
||||
MOZ_LIBART_CFLAGS = @MOZ_LIBART_CFLAGS@
|
||||
MOZ_ENABLE_CAIRO = @MOZ_ENABLE_CAIRO@
|
||||
MOZ_CAIRO_CFLAGS = @MOZ_CAIRO_CFLAGS@
|
||||
TX_EXE = @TX_EXE@
|
||||
|
||||
|
@ -3178,6 +3178,9 @@ MOZ_ARG_ENABLE_BOOL(cairo,
|
||||
[ --enable-cairo Enable Cairo-specific features (Canvas)],
|
||||
MOZ_ENABLE_CAIRO=1,
|
||||
MOZ_ENABLE_CAIRO= )
|
||||
if test "$MOZ_ENABLE_CAIRO"; then
|
||||
AC_DEFINE(MOZ_ENABLE_CAIRO)
|
||||
fi
|
||||
|
||||
fi # SKIP_LIBRARY_CHECKS
|
||||
|
||||
|
@ -2915,7 +2915,7 @@ nsDocument::GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult)
|
||||
contractID += "-listbox";
|
||||
else if (tag == nsXULAtoms::scrollbox)
|
||||
contractID += "-scrollbox";
|
||||
#ifndef MOZ_ENABLE_CAIRO
|
||||
#ifdef MOZ_ENABLE_CAIRO
|
||||
else if (tag == nsXULAtoms::canvas)
|
||||
contractID += "-canvas";
|
||||
#endif
|
||||
|
@ -43,3 +43,9 @@ interface nsICanvasBoxObject : nsISupports
|
||||
nsISupports getContext(in string aContext);
|
||||
};
|
||||
|
||||
[scriptable, uuid(1d6f084b-cb1d-4068-a20f-df11f7955017)]
|
||||
interface nsICanvasFrame : nsISupports
|
||||
{
|
||||
nsISupports getContext(in string aContext);
|
||||
};
|
||||
|
||||
|
@ -38,10 +38,25 @@
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIDOMHTMLImageElement;
|
||||
interface nsIBoxObject;
|
||||
|
||||
[scriptable, uuid(bbb20a59-524e-4662-981e-5e142814b20c)]
|
||||
interface nsICanvasGradient : nsISupports
|
||||
{
|
||||
void addColorStop(in float offset, in DOMString color);
|
||||
};
|
||||
|
||||
[scriptable, uuid(21dea65c-5c08-4eb1-ac82-81fe95be77b8)]
|
||||
interface nsICanvasPattern : nsISupports
|
||||
{
|
||||
};
|
||||
|
||||
[scriptable, uuid(fd1e2245-8d8c-4146-bf47-fb84ddd6fca0)]
|
||||
interface nsICanvasRenderingContext2D : nsISupports
|
||||
{
|
||||
// back-reference to the canvas object
|
||||
readonly attribute nsIBoxObject canvas;
|
||||
|
||||
// state
|
||||
void save();
|
||||
void restore();
|
||||
@ -51,11 +66,28 @@ interface nsICanvasRenderingContext2D : nsISupports
|
||||
void rotate(in float angle);
|
||||
void translate(in float x, in float y);
|
||||
|
||||
// colors
|
||||
// XXX how does setAlpha affect alpha set by StrokeColor and FillColor?
|
||||
void setStrokeColor(in string color);
|
||||
void setFillColor(in string color);
|
||||
void setAlpha(in float alpha);
|
||||
// compositing
|
||||
attribute float globalAlpha; /* default 1.0 -- opaque */
|
||||
attribute DOMString globalCompositeOperation; /* default "over" */
|
||||
|
||||
// colors and styles
|
||||
attribute DOMString strokeStyle;
|
||||
attribute DOMString fillStyle;
|
||||
|
||||
nsICanvasGradient createLinearGradient (in float x0, in float y0, in float x1, in float y1);
|
||||
nsICanvasGradient createRadialGradient(in float x0, in float y0, in float r0, in float x1, in float y1, in float r1);
|
||||
nsICanvasPattern createPattern(in nsIDOMHTMLImageElement image, in DOMString repetition);
|
||||
|
||||
attribute float lineWidth; /* default 1 */
|
||||
attribute DOMString lineCap; /* "butt", "round", "square" (default) */
|
||||
attribute DOMString lineJoin; /* "round", "bevel", "miter" (default) */
|
||||
attribute float miterLimit; /* default 10 */
|
||||
|
||||
// shadows
|
||||
attribute float shadowOffsetX;
|
||||
attribute float shadowOffsetY;
|
||||
attribute float shadowBlur;
|
||||
attribute DOMString shadowColor;
|
||||
|
||||
// rects
|
||||
void clearRect(in float x, in float y, in float w, in float h);
|
||||
@ -65,42 +97,24 @@ interface nsICanvasRenderingContext2D : nsISupports
|
||||
// path API
|
||||
void beginPath();
|
||||
void closePath();
|
||||
void fillPath();
|
||||
void strokePath();
|
||||
|
||||
void moveTo(in float x, in float y);
|
||||
void lineTo(in float x, in float y);
|
||||
void quadraticCurveTo(in float cpx, in float cpy, in float x, in float y);
|
||||
void bezierCurveTo(in float cp1x, in float cp1y, in float cp2x, in float cp2y, in float x, in float y);
|
||||
void arcTo(in float x1, in float y1, in float x2, in float y2, in float radius);
|
||||
void arc(in float x, in float y, in float r, in float startAngle, in float endAngle, in boolean clockwise);
|
||||
void rect(in float x, in float y, in float w, in float h);
|
||||
|
||||
void fill();
|
||||
void stroke();
|
||||
void clip();
|
||||
|
||||
void moveToPoint(in float x, in float y);
|
||||
void addLineToPoint(in float x, in float y);
|
||||
void addQuadraticCurveToPoint(in float cpx, in float cpy, in float x, in float y);
|
||||
void addBezierCurveToPoint(in float cp1x, in float cp1y, in float cp2x, in float cp2y, in float x, in float y);
|
||||
void addArcToPoint(in float x1, in float y1, in float x2, in float y2, in float radius);
|
||||
void addArc(in float x, in float y, in float r, in float startAngle, in float endAngle, in boolean clockwise);
|
||||
void addRect(in float x, in float y, in float w, in float h);
|
||||
|
||||
// line caps/joins
|
||||
void setLineWidth(in float width);
|
||||
void setLineCap(in string capstyle); // "round" "square"
|
||||
void setLineJoin(in string joinstyle); // "round" "bevel" "miter"
|
||||
void setMiterLimit(in float limit);
|
||||
|
||||
// image api
|
||||
void drawImage(in nsIDOMHTMLImageElement image, in long x, in long y, in long w, in long h, in string composite);
|
||||
void drawImageFromRect(in nsIDOMHTMLImageElement image,
|
||||
in long sx, in long sy, in long sw, in long sh,
|
||||
in long dx, in long dy, in long dw, in long dh,
|
||||
in string composite);
|
||||
|
||||
// shadow api (uh..)
|
||||
void setShadow(in float width, in float height, in float blur, in string color);
|
||||
void clearShadow();
|
||||
|
||||
// compositing
|
||||
void setCompositeOperation(in string composite);
|
||||
|
||||
//
|
||||
// additions
|
||||
//
|
||||
|
||||
// nsIHTMLImageElement getImage(); // snapshot the current canvas
|
||||
|
||||
void drawImage();
|
||||
/*
|
||||
void drawImage(in HTMLImageElement image, in float dx, in float dy);
|
||||
void drawImage(in HTMLImageElement image, in float dx, in float dy, in float dw, in float dh);
|
||||
void drawImage(in HTMLImageElement image, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh);
|
||||
*/
|
||||
};
|
||||
|
@ -129,6 +129,7 @@ ifdef MOZ_ENABLE_CAIRO
|
||||
CPPSRCS += \
|
||||
nsCanvasFrame.cpp \
|
||||
nsCanvasBoxObject.cpp \
|
||||
nsCanvasRenderingContext2D.cpp \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
|
@ -51,7 +51,7 @@ public:
|
||||
nsCanvasBoxObject();
|
||||
virtual ~nsCanvasBoxObject();
|
||||
|
||||
nsICanvasBoxObject* GetFrameBoxObject();
|
||||
nsICanvasFrame* GetCanvasFrame();
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
@ -81,13 +81,13 @@ nsCanvasBoxObject::~nsCanvasBoxObject()
|
||||
{
|
||||
}
|
||||
|
||||
inline nsICanvasBoxObject *
|
||||
nsCanvasBoxObject::GetFrameBoxObject()
|
||||
inline nsICanvasFrame *
|
||||
nsCanvasBoxObject::GetCanvasFrame()
|
||||
{
|
||||
nsIFrame *frame = GetFrame();
|
||||
nsICanvasBoxObject *frameCanvasBoxObject = nsnull;
|
||||
CallQueryInterface(frame, &frameCanvasBoxObject);
|
||||
return frameCanvasBoxObject;
|
||||
nsICanvasFrame *canvasFrame = nsnull;
|
||||
CallQueryInterface(frame, &canvasFrame);
|
||||
return canvasFrame;
|
||||
}
|
||||
|
||||
// nsPIBoxObject
|
||||
@ -113,9 +113,9 @@ nsCanvasBoxObject::InvalidatePresentationStuff()
|
||||
NS_IMETHODIMP
|
||||
nsCanvasBoxObject::GetContext(const char *aContext, nsISupports **aResult)
|
||||
{
|
||||
nsICanvasBoxObject *canvas = GetFrameBoxObject();
|
||||
nsICanvasFrame *canvas = GetCanvasFrame();
|
||||
if (canvas)
|
||||
return GetFrameBoxObject()->GetContext(aContext, aResult);
|
||||
return canvas->GetContext(aContext, aResult);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ NS_NewCanvasXULFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
||||
// QueryInterface
|
||||
//
|
||||
NS_INTERFACE_MAP_BEGIN(nsCanvasFrame)
|
||||
NS_INTERFACE_MAP_ENTRY(nsICanvasBoxObject)
|
||||
NS_INTERFACE_MAP_ENTRY(nsICanvasFrame)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsLeafBoxFrame)
|
||||
|
||||
nsCanvasFrame::nsCanvasFrame(nsIPresShell* aPresShell)
|
||||
|
@ -44,8 +44,8 @@
|
||||
#include "nsICanvasRenderingContext.h"
|
||||
|
||||
class nsCanvasFrame :
|
||||
public nsLeafBoxFrame,
|
||||
public nsICanvasBoxObject
|
||||
public nsLeafBoxFrame, // this must be the first thing we inherit from, due to nsFrame operator delete business
|
||||
public nsICanvasFrame
|
||||
{
|
||||
public:
|
||||
nsCanvasFrame(nsIPresShell* aPresShell);
|
||||
@ -68,8 +68,8 @@ public:
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsICanvasBoxObject interface
|
||||
NS_DECL_NSICANVASBOXOBJECT
|
||||
// nsICanvasFrame interface
|
||||
NS_DECL_NSICANVASFRAME
|
||||
|
||||
protected:
|
||||
nsPresContext* mPresContext;
|
||||
|
@ -49,6 +49,10 @@
|
||||
#include "nsIDOMHTMLImageElement.h"
|
||||
#include "nsIImageLoadingContent.h"
|
||||
|
||||
#include "nsPrintfCString.h"
|
||||
|
||||
#include "nsReadableUtils.h"
|
||||
|
||||
#include <cairo.h>
|
||||
|
||||
class nsCanvasRenderingContext2D :
|
||||
@ -114,12 +118,15 @@ NS_NewCanvasRenderingContext2D(nsICanvasRenderingContext2D** aResult)
|
||||
NS_IMPL_ISUPPORTS2(nsCanvasRenderingContext2D, nsICanvasRenderingContext2D, nsICanvasRenderingContext)
|
||||
|
||||
static PRBool
|
||||
ColorStringToColor (const char *str, nscolor &color)
|
||||
ColorStringToColor (const nsAString& style, nscolor &color)
|
||||
{
|
||||
if (!str || !str[0])
|
||||
nsCAutoString str;
|
||||
str.Assign(NS_ConvertUTF16toUTF8(style));
|
||||
|
||||
if (str.IsEmpty())
|
||||
return PR_FALSE;
|
||||
|
||||
int slen = nsCRT::strlen(str);
|
||||
int slen = str.Length();
|
||||
|
||||
if (str[0] == '#') {
|
||||
unsigned int shift = 0;
|
||||
@ -139,7 +146,7 @@ ColorStringToColor (const char *str, nscolor &color)
|
||||
} else if (slen == 7) {
|
||||
char *ss = nsnull;
|
||||
unsigned long l;
|
||||
l = strtoul (str+1, &ss, 16);
|
||||
l = strtoul (nsPromiseFlatCString(str).get()+1, &ss, 16);
|
||||
if (*ss != 0) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
@ -150,11 +157,11 @@ ColorStringToColor (const char *str, nscolor &color)
|
||||
}
|
||||
}
|
||||
|
||||
if (nsCRT::strncmp(str, "rgb(", 4) == 0) {
|
||||
if (StringBeginsWith(style, NS_LITERAL_STRING("rgb("))) {
|
||||
// ...
|
||||
}
|
||||
|
||||
if (NS_ColorNameToRGB(NS_ConvertUTF8toUTF16(str), &color))
|
||||
if (NS_ColorNameToRGB(style, &color))
|
||||
return PR_TRUE;
|
||||
|
||||
return PR_FALSE;
|
||||
@ -192,11 +199,9 @@ nsCanvasRenderingContext2D::SetCairoColor(nscolor c)
|
||||
double r = double(NS_GET_R(c) / 255.0);
|
||||
double g = double(NS_GET_G(c) / 255.0);
|
||||
double b = double(NS_GET_B(c) / 255.0);
|
||||
double a = double(NS_GET_A(c) / 255.0);
|
||||
|
||||
// fprintf (stderr, "::SetCairoColor r: %g g: %g b: %g a: %g\n", r, g, b, a);
|
||||
cairo_set_rgb_color (mCairo, r, g, b);
|
||||
cairo_set_alpha (mCairo, a);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -314,9 +319,10 @@ nsCanvasRenderingContext2D::Paint(nsPresContext* aPresContext,
|
||||
mDirty = PR_FALSE;
|
||||
}
|
||||
|
||||
nsPoint dst = mCanvasFrame->GetPosition();
|
||||
nsPoint dstpt = mCanvasFrame->GetPosition();
|
||||
nsRect src(0, 0, NSIntPixelsToTwips(mWidth, mPixelsToTwips), NSIntPixelsToTwips(mHeight, mPixelsToTwips));
|
||||
return aRenderingContext.DrawImage(mImageContainer, &src, &dst);
|
||||
nsRect dst(dstpt.x, dstpt.y, src.width, src.height);
|
||||
return aRenderingContext.DrawImage(mImageContainer, src, dst);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@ -326,6 +332,13 @@ nsCanvasRenderingContext2D::Paint(nsPresContext* aPresContext,
|
||||
// nsCanvasRenderingContext2D impl
|
||||
//
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::GetCanvas(nsIBoxObject **canvas)
|
||||
{
|
||||
//NS_IF_ADDREF(*canvas = mCanvasFrame);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
//
|
||||
// state
|
||||
//
|
||||
@ -374,37 +387,128 @@ nsCanvasRenderingContext2D::Translate(float x, float y)
|
||||
//
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::SetStrokeColor(const char* color)
|
||||
nsCanvasRenderingContext2D::SetGlobalAlpha(float globalAlpha)
|
||||
{
|
||||
nscolor c;
|
||||
if (ColorStringToColor(color, c)) {
|
||||
mStrokeColor = (mStrokeColor & 0xff000000) | (c & 0x00ffffff);
|
||||
cairo_set_alpha (mCairo, globalAlpha);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::GetGlobalAlpha(float *globalAlpha)
|
||||
{
|
||||
double d = cairo_current_alpha(mCairo);
|
||||
*globalAlpha = (float) d;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::SetStrokeStyle(const nsAString& style)
|
||||
{
|
||||
if (ColorStringToColor(style, mStrokeColor))
|
||||
return NS_OK;
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::SetFillColor(const char* color)
|
||||
nsCanvasRenderingContext2D::GetStrokeStyle(nsAString& style)
|
||||
{
|
||||
nscolor c;
|
||||
if (ColorStringToColor(color, c)) {
|
||||
mFillColor = (mFillColor & 0xff000000) | (c & 0x00ffffff);
|
||||
style.Assign(NS_ConvertUTF8toUTF16(nsPrintfCString(100, "#%08x", mStrokeColor)));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::SetFillStyle(const nsAString& style)
|
||||
{
|
||||
if (ColorStringToColor(style, mFillColor))
|
||||
return NS_OK;
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::SetAlpha(float alpha)
|
||||
nsCanvasRenderingContext2D::GetFillStyle(nsAString& style)
|
||||
{
|
||||
// XXX change the alpha of both the stroke and fill colors
|
||||
PRUint8 alpha8 = (PRUint8) (alpha * 255.0);
|
||||
mFillColor = (mFillColor & 0x00ffffff) | (alpha8 << 24);
|
||||
mStrokeColor = (mStrokeColor & 0x00ffffff) | (alpha8 << 24);
|
||||
style.Assign(NS_ConvertUTF8toUTF16(nsPrintfCString(100, "#%08x", mFillColor)));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//
|
||||
// gradients and patterns
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::CreateLinearGradient(float x0, float y0, float x1, float y1,
|
||||
nsICanvasGradient **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::CreateRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1,
|
||||
nsICanvasGradient **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::CreatePattern(nsIDOMHTMLImageElement *image,
|
||||
const nsAString& repetition,
|
||||
nsICanvasPattern **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
//
|
||||
// shadows
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::SetShadowOffsetX(float x)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::GetShadowOffsetX(float *x)
|
||||
{
|
||||
*x = 0.0f;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::SetShadowOffsetY(float y)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::GetShadowOffsetY(float *y)
|
||||
{
|
||||
*y = 0.0f;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::SetShadowBlur(float blur)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::GetShadowBlur(float *blur)
|
||||
{
|
||||
*blur = 0.0f;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::SetShadowColor(const nsAString& color)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::GetShadowColor(nsAString& color)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -471,7 +575,7 @@ nsCanvasRenderingContext2D::ClosePath()
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::FillPath()
|
||||
nsCanvasRenderingContext2D::Fill()
|
||||
{
|
||||
SetCairoColor(mFillColor);
|
||||
cairo_fill(mCairo);
|
||||
@ -479,7 +583,7 @@ nsCanvasRenderingContext2D::FillPath()
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::StrokePath()
|
||||
nsCanvasRenderingContext2D::Stroke()
|
||||
{
|
||||
SetCairoColor(mStrokeColor);
|
||||
cairo_stroke(mCairo);
|
||||
@ -494,28 +598,28 @@ nsCanvasRenderingContext2D::Clip()
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::MoveToPoint(float x, float y)
|
||||
nsCanvasRenderingContext2D::MoveTo(float x, float y)
|
||||
{
|
||||
cairo_move_to(mCairo, x, y);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::AddLineToPoint(float x, float y)
|
||||
nsCanvasRenderingContext2D::LineTo(float x, float y)
|
||||
{
|
||||
cairo_line_to(mCairo, x, y);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::AddQuadraticCurveToPoint(float cpx, float cpy, float x, float y)
|
||||
nsCanvasRenderingContext2D::QuadraticCurveTo(float cpx, float cpy, float x, float y)
|
||||
{
|
||||
cairo_curve_to(mCairo, cpx, cpy, cpx, cpy, x, y);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::AddBezierCurveToPoint(float cp1x, float cp1y,
|
||||
nsCanvasRenderingContext2D::BezierCurveTo(float cp1x, float cp1y,
|
||||
float cp2x, float cp2y,
|
||||
float x, float y)
|
||||
{
|
||||
@ -524,13 +628,13 @@ nsCanvasRenderingContext2D::AddBezierCurveToPoint(float cp1x, float cp1y,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::AddArcToPoint(float x1, float y1, float x2, float y2, float radius)
|
||||
nsCanvasRenderingContext2D::ArcTo(float x1, float y1, float x2, float y2, float radius)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::AddArc(float x, float y, float r, float startAngle, float endAngle, int clockwise)
|
||||
nsCanvasRenderingContext2D::Arc(float x, float y, float r, float startAngle, float endAngle, int clockwise)
|
||||
{
|
||||
if (clockwise)
|
||||
cairo_arc (mCairo, x, y, r, startAngle, endAngle);
|
||||
@ -540,7 +644,7 @@ nsCanvasRenderingContext2D::AddArc(float x, float y, float r, float startAngle,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::AddRect(float x, float y, float w, float h)
|
||||
nsCanvasRenderingContext2D::Rect(float x, float y, float w, float h)
|
||||
{
|
||||
cairo_rectangle (mCairo, x, y, w, h);
|
||||
return NS_OK;
|
||||
@ -558,13 +662,21 @@ nsCanvasRenderingContext2D::SetLineWidth(float width)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::SetLineCap(const char *capstyle)
|
||||
nsCanvasRenderingContext2D::GetLineWidth(float *width)
|
||||
{
|
||||
double d = cairo_current_line_width(mCairo);
|
||||
*width = (float) d;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::SetLineCap(const nsAString& capstyle)
|
||||
{
|
||||
cairo_line_cap_t cap;
|
||||
|
||||
if (nsCRT::strcmp(capstyle, "round") == 0)
|
||||
if (capstyle.EqualsLiteral("round"))
|
||||
cap = CAIRO_LINE_CAP_ROUND;
|
||||
else if (nsCRT::strcmp(capstyle, "square") == 0)
|
||||
else if (capstyle.EqualsLiteral("square"))
|
||||
cap = CAIRO_LINE_CAP_SQUARE;
|
||||
else
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
@ -574,15 +686,30 @@ nsCanvasRenderingContext2D::SetLineCap(const char *capstyle)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::SetLineJoin(const char *joinstyle)
|
||||
nsCanvasRenderingContext2D::GetLineCap(nsAString& capstyle)
|
||||
{
|
||||
cairo_line_cap_t cap = cairo_current_line_cap(mCairo);
|
||||
|
||||
if (cap == CAIRO_LINE_CAP_ROUND)
|
||||
capstyle.AssignLiteral("round");
|
||||
else if (cap == CAIRO_LINE_CAP_SQUARE)
|
||||
capstyle.AssignLiteral("square");
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::SetLineJoin(const nsAString& joinstyle)
|
||||
{
|
||||
cairo_line_join_t j;
|
||||
|
||||
if (nsCRT::strcmp(joinstyle, "round") == 0)
|
||||
if (joinstyle.EqualsLiteral("round"))
|
||||
j = CAIRO_LINE_JOIN_ROUND;
|
||||
else if (nsCRT::strcmp(joinstyle, "bevel") == 0)
|
||||
else if (joinstyle.EqualsLiteral("bevel"))
|
||||
j = CAIRO_LINE_JOIN_BEVEL;
|
||||
else if (nsCRT::strcmp(joinstyle, "miter") == 0)
|
||||
else if (joinstyle.EqualsLiteral("miter"))
|
||||
j = CAIRO_LINE_JOIN_MITER;
|
||||
else
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
@ -591,6 +718,23 @@ nsCanvasRenderingContext2D::SetLineJoin(const char *joinstyle)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::GetLineJoin(nsAString& joinstyle)
|
||||
{
|
||||
cairo_line_join_t j = cairo_current_line_join(mCairo);
|
||||
|
||||
if (j == CAIRO_LINE_JOIN_ROUND)
|
||||
joinstyle.AssignLiteral("round");
|
||||
else if (j == CAIRO_LINE_JOIN_BEVEL)
|
||||
joinstyle.AssignLiteral("bevel");
|
||||
else if (j == CAIRO_LINE_JOIN_MITER)
|
||||
joinstyle.AssignLiteral("miter");
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::SetMiterLimit(float miter)
|
||||
{
|
||||
@ -598,13 +742,22 @@ nsCanvasRenderingContext2D::SetMiterLimit(float miter)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::GetMiterLimit(float *miter)
|
||||
{
|
||||
double d = cairo_current_miter_limit(mCairo);
|
||||
*miter = (float) d;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//
|
||||
// image
|
||||
//
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::DrawImage(nsIDOMHTMLImageElement *aImage, int x, int y, int w, int h, const char *composite)
|
||||
nsCanvasRenderingContext2D::DrawImage()
|
||||
{
|
||||
#if 0
|
||||
nsCOMPtr<nsIImageLoadingContent> contentImage(aImage);
|
||||
nsCOMPtr<imgIRequest> request;
|
||||
contentImage->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST, getter_AddRefs(request));
|
||||
@ -713,35 +866,18 @@ nsCanvasRenderingContext2D::DrawImage(nsIDOMHTMLImageElement *aImage, int x, int
|
||||
cairo_surface_destroy(surface);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::DrawImageFromRect(nsIDOMHTMLImageElement *aImage, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, const char *composite)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// shadows..
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::SetShadow(float width, float height, float blur, const char *color)
|
||||
{
|
||||
#endif
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::ClearShadow()
|
||||
nsCanvasRenderingContext2D::SetGlobalCompositeOperation(const nsAString& op)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::SetCompositeOperation(const char *composite)
|
||||
{
|
||||
cairo_operator_t the_op;
|
||||
cairo_operator_t cairo_op;
|
||||
|
||||
#define CANVAS_OP_TO_CAIRO_OP(cvsop,cairoop) \
|
||||
if (nsCRT::strcmp (composite, cvsop) == 0) \
|
||||
the_op = CAIRO_OPERATOR_##cairoop;
|
||||
if (op.EqualsLiteral(cvsop)) \
|
||||
cairo_op = CAIRO_OPERATOR_##cairoop;
|
||||
|
||||
CANVAS_OP_TO_CAIRO_OP("clear", CLEAR)
|
||||
else CANVAS_OP_TO_CAIRO_OP("copy", SRC)
|
||||
@ -759,6 +895,38 @@ nsCanvasRenderingContext2D::SetCompositeOperation(const char *composite)
|
||||
else CANVAS_OP_TO_CAIRO_OP("over", OVER)
|
||||
else return NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
cairo_set_operator(mCairo, the_op);
|
||||
#undef CANVAS_OP_TO_CAIRO_OP
|
||||
|
||||
cairo_set_operator(mCairo, cairo_op);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::GetGlobalCompositeOperation(nsAString& op)
|
||||
{
|
||||
cairo_operator_t cairo_op = cairo_current_operator(mCairo);
|
||||
|
||||
#define CANVAS_OP_TO_CAIRO_OP(cvsop,cairoop) \
|
||||
if (cairo_op == CAIRO_OPERATOR_##cairoop) \
|
||||
op.AssignLiteral(cvsop);
|
||||
|
||||
CANVAS_OP_TO_CAIRO_OP("clear", CLEAR)
|
||||
else CANVAS_OP_TO_CAIRO_OP("copy", SRC)
|
||||
else CANVAS_OP_TO_CAIRO_OP("darker", SATURATE) // XXX
|
||||
else CANVAS_OP_TO_CAIRO_OP("destination-atop", ATOP_REVERSE)
|
||||
else CANVAS_OP_TO_CAIRO_OP("destination-in", IN_REVERSE)
|
||||
else CANVAS_OP_TO_CAIRO_OP("destination-out", OUT_REVERSE)
|
||||
else CANVAS_OP_TO_CAIRO_OP("destination-over", OVER_REVERSE)
|
||||
else CANVAS_OP_TO_CAIRO_OP("lighter", SATURATE)
|
||||
else CANVAS_OP_TO_CAIRO_OP("source-atop", ATOP)
|
||||
else CANVAS_OP_TO_CAIRO_OP("source-in", IN)
|
||||
else CANVAS_OP_TO_CAIRO_OP("source-out", OUT)
|
||||
else CANVAS_OP_TO_CAIRO_OP("source-over", OVER)
|
||||
else CANVAS_OP_TO_CAIRO_OP("xor", XOR)
|
||||
else CANVAS_OP_TO_CAIRO_OP("over", OVER)
|
||||
else return NS_ERROR_FAILURE;
|
||||
|
||||
#undef CANVAS_OP_TO_CAIRO_OP
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "nsIFrame.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "nsIRenderingContext.h"
|
||||
#include "nsIBoxObject.h"
|
||||
|
||||
#define NS_ICANVASRENDERINGCONTEXT_IID \
|
||||
{ 0x753a56cb, 0xf8ca, 0x4deb, { 0xb8, 0x75, 0xf2, 0x80, 0xeb, 0x91, 0x2c, 0x56 } }
|
||||
|
Loading…
Reference in New Issue
Block a user