b=279306, update canvas API to reflect latest standard spec; r=stuart,sr=shaver

This commit is contained in:
vladimir%pobox.com 2005-01-26 02:08:35 +00:00
Родитель 37d2c1066e
Коммит d5febfb9de
12 изменённых файлов: 413 добавлений и 832 удалений

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

@ -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@

338
configure поставляемый

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -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

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

@ -1,45 +0,0 @@
/* -*- 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.org code.
*
* The Initial Developer of the Original Code is
* Vladimir Vukicevic <vladimir@pobox.com>
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#include "nsISupports.idl"
[scriptable, uuid(6990a6e4-1c9d-4790-a7cb-2e32c8407a66)]
interface nsICanvasBoxObject : nsISupports
{
nsISupports getContext(in string aContext);
};

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

@ -1,106 +0,0 @@
/* -*- 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.org code.
*
* The Initial Developer of the Original Code is
* Vladimir Vukicevic <vladimir@pobox.com>
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#include "nsISupports.idl"
interface nsIDOMHTMLImageElement;
[scriptable, uuid(fd1e2245-8d8c-4146-bf47-fb84ddd6fca0)]
interface nsICanvasRenderingContext2D : nsISupports
{
// state
void save();
void restore();
// transformations
void scale(in float x, in float y);
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);
// rects
void clearRect(in float x, in float y, in float w, in float h);
void fillRect(in float x, in float y, in float w, in float h);
void strokeRect(in float x, in float y, in float w, in float h);
// path API
void beginPath();
void closePath();
void fillPath();
void strokePath();
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
};

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

@ -129,6 +129,7 @@ ifdef MOZ_ENABLE_CAIRO
CPPSRCS += \
nsCanvasFrame.cpp \
nsCanvasBoxObject.cpp \
nsCanvasRenderingContext2D.cpp \
$(NULL)
endif

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

@ -1,131 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Vladimir Vukicevic <vladimir@pobox.com>
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#include "nsICanvasBoxObject.h"
#include "nsCanvasFrame.h"
#include "nsCOMPtr.h"
#include "nsPresContext.h"
#include "nsIPresShell.h"
#include "nsIBoxObject.h"
#include "nsIFrame.h"
#include "nsBoxObject.h"
class nsCanvasBoxObject : public nsICanvasBoxObject, public nsBoxObject
{
public:
nsCanvasBoxObject();
virtual ~nsCanvasBoxObject();
nsICanvasBoxObject* GetFrameBoxObject();
// nsISupports interface
NS_DECL_ISUPPORTS_INHERITED
// nsICanvasBoxObject interface
NS_DECL_NSICANVASBOXOBJECT
// nsPIBoxObject interface
NS_IMETHOD Init(nsIContent* aContent, nsIPresShell* aPresShell);
NS_IMETHOD SetDocument(nsIDocument* aDocument);
NS_IMETHOD InvalidatePresentationStuff();
};
NS_INTERFACE_MAP_BEGIN(nsCanvasBoxObject)
NS_INTERFACE_MAP_ENTRY(nsICanvasBoxObject)
NS_INTERFACE_MAP_END_INHERITING(nsBoxObject)
NS_IMPL_ADDREF(nsCanvasBoxObject)
NS_IMPL_RELEASE(nsCanvasBoxObject)
nsCanvasBoxObject::nsCanvasBoxObject()
{
NS_INIT_ISUPPORTS();
}
nsCanvasBoxObject::~nsCanvasBoxObject()
{
}
inline nsICanvasBoxObject *
nsCanvasBoxObject::GetFrameBoxObject()
{
nsIFrame *frame = GetFrame();
nsICanvasBoxObject *frameCanvasBoxObject = nsnull;
CallQueryInterface(frame, &frameCanvasBoxObject);
return frameCanvasBoxObject;
}
// nsPIBoxObject
NS_IMETHODIMP
nsCanvasBoxObject::Init(nsIContent* aContent, nsIPresShell* aPresShell)
{
return nsBoxObject::Init(aContent, aPresShell);
}
NS_IMETHODIMP
nsCanvasBoxObject::SetDocument(nsIDocument* aDocument)
{
return nsBoxObject::SetDocument(aDocument);
}
NS_IMETHODIMP
nsCanvasBoxObject::InvalidatePresentationStuff()
{
return nsBoxObject::InvalidatePresentationStuff();
}
// nsICanvasBoxObject
NS_IMETHODIMP
nsCanvasBoxObject::GetContext(const char *aContext, nsISupports **aResult)
{
nsICanvasBoxObject *canvas = GetFrameBoxObject();
if (canvas)
return GetFrameBoxObject()->GetContext(aContext, aResult);
return NS_ERROR_FAILURE;
}
// creation
nsresult
NS_NewCanvasBoxObject(nsIBoxObject **aResult)
{
*aResult = new nsCanvasBoxObject;
if (!*aResult)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aResult);
return NS_OK;
}

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

@ -1,171 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Vladimir Vukicevic <vladimir@pobox.com>
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#include "nsCanvasFrame.h"
#include "nsICanvasRenderingContext.h"
#include "nsIComponentManager.h"
nsresult
NS_NewCanvasXULFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
{
NS_ENSURE_ARG_POINTER(aPresShell);
NS_ENSURE_ARG_POINTER(aNewFrame);
nsCanvasFrame* frame = new (aPresShell) nsCanvasFrame(aPresShell);
if (!frame)
return NS_ERROR_OUT_OF_MEMORY;
*aNewFrame = frame;
return NS_OK;
}
//
// QueryInterface
//
NS_INTERFACE_MAP_BEGIN(nsCanvasFrame)
NS_INTERFACE_MAP_ENTRY(nsICanvasBoxObject)
NS_INTERFACE_MAP_END_INHERITING(nsLeafBoxFrame)
nsCanvasFrame::nsCanvasFrame(nsIPresShell* aPresShell)
: nsLeafBoxFrame(aPresShell), mPresContext(nsnull)
{
}
nsCanvasFrame::~nsCanvasFrame()
{
}
NS_IMETHODIMP_(nsrefcnt)
nsCanvasFrame::AddRef(void)
{
// don't do this!
return 0;
}
NS_IMETHODIMP_(nsrefcnt)
nsCanvasFrame::Release(void)
{
// don't do this!
return 0;
}
//
// overriden nsIFrame stuff
//
NS_IMETHODIMP
nsCanvasFrame::Init(nsPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
mPresContext = aPresContext;
return nsLeafBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
}
NS_IMETHODIMP
nsCanvasFrame::Destroy(nsPresContext* aPresContext)
{
return nsLeafBoxFrame::Destroy(aPresContext);
}
NS_IMETHODIMP
nsCanvasFrame::GetPrefSize(nsBoxLayoutState& aState, nsSize& aSize)
{
aSize.width = 0;
aSize.height = 0;
AddBorderAndPadding(aSize);
AddInset(aSize);
nsIBox::AddCSSPrefSize(aState, this, aSize);
return NS_OK;
}
NS_IMETHODIMP
nsCanvasFrame::Paint(nsPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer,
PRUint32 aFlags)
{
// fprintf (stderr, "+++ nsCanvasFrame::Paint\n");
if (!mRenderingContext)
return NS_OK;
return mRenderingContext->Paint(aPresContext, aRenderingContext,
aDirtyRect, aWhichLayer,
aFlags);
}
NS_IMETHODIMP
nsCanvasFrame::GetContext(const char* aContext, nsISupports** aResult)
{
NS_ENSURE_ARG(aContext);
NS_ENSURE_ARG_POINTER(aResult);
nsresult rv;
nsCAutoString contractID("@mozilla.org/layout/canvas-rendering-context?name=");
contractID += aContext;
contractID += ";1";
if (mRenderingContext) {
if (! mRenderingContextName.Equals(aContext))
return NS_ERROR_FAILURE;
} else {
mRenderingContext = do_CreateInstance(contractID.get());
if (!mRenderingContext)
return NS_ERROR_FAILURE;
rv = mRenderingContext->Init(this, mPresContext);
fprintf (stderr, "nsCanvasRenderingContextInternal::Init returned: 0x%08x\n", rv);
if (NS_FAILED(rv)) {
mRenderingContext = nsnull;
return rv;
}
mRenderingContextName.Assign(aContext);
}
*aResult = mRenderingContext.get();
NS_ADDREF(*aResult);
return NS_OK;
}

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

@ -1,80 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Vladimir Vukicevic <vladimir@pobox.com>
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 NSCANVASFRAME__H__
#define NSCANVASFRAME__H__
#include "nscore.h"
#include "nsLeafBoxFrame.h"
#include "nsICanvasBoxObject.h"
#include "nsICanvasRenderingContext.h"
class nsCanvasFrame :
public nsLeafBoxFrame,
public nsICanvasBoxObject
{
public:
nsCanvasFrame(nsIPresShell* aPresShell);
virtual ~nsCanvasFrame();
// overriddenmethods from nsIFrame
NS_IMETHOD Init(nsPresContext* aPresContext, nsIContent* aContent,
nsIFrame* aParent, nsStyleContext* aContext, nsIFrame* aPrevInFlow);
NS_IMETHOD Destroy(nsPresContext* aPresContext);
NS_IMETHOD GetPrefSize(nsBoxLayoutState& aState, nsSize& aSize);
NS_IMETHOD Paint(nsPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer,
PRUint32 aFlags);
// nsISupports interface
NS_DECL_ISUPPORTS
// nsICanvasBoxObject interface
NS_DECL_NSICANVASBOXOBJECT
protected:
nsPresContext* mPresContext;
nsCOMPtr<nsICanvasRenderingContext> mRenderingContext;
nsCString mRenderingContextName;
};
#endif /* NSCANVASFRAME__H__ */

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

@ -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,43 +598,43 @@ 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,
float cp2x, float cp2y,
float x, float y)
nsCanvasRenderingContext2D::BezierCurveTo(float cp1x, float cp1y,
float cp2x, float cp2y,
float x, float y)
{
cairo_curve_to(mCairo, cp1x, cp1y, cp2x, cp2y, x, y);
return NS_OK;
}
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;
}

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

@ -1,65 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Vladimir Vukicevic <vladimir@pobox.com>
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 NSICANVASRENDERINGCONTEXT__H__
#define NSICANVASRENDERINGCONTEXT__H__
#include "nsISupports.h"
#include "nsIFrame.h"
#include "nsPresContext.h"
#include "nsIRenderingContext.h"
#define NS_ICANVASRENDERINGCONTEXT_IID \
{ 0x753a56cb, 0xf8ca, 0x4deb, { 0xb8, 0x75, 0xf2, 0x80, 0xeb, 0x91, 0x2c, 0x56 } }
class nsCanvasFrame;
class nsICanvasRenderingContext : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICANVASRENDERINGCONTEXT_IID)
virtual nsresult Init(nsCanvasFrame* aCanvasFrame, nsPresContext* aPresContext) = 0;
virtual nsresult Paint(nsPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer,
PRUint32 aFlags) = 0;
};
#endif /* NSICANVASRENDERINGCONTEXT__H__ */