Closed Bug 800553 Opened 12 years ago Closed 11 years ago

Convert the canvas helper classes to the new dom bindings

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 856472

People

(Reporter: nrc, Assigned: sankha)

References

Details

Attachments

(2 files, 4 obsolete files)

Canvas now uses the new dom bindings but its helper classes (TextMetrics, CavnasGradient, etc.) use the old ones. They should be converted.
This bug involves creating WebIDL interfaces (see [1]) to replace nsIDOMCanvasGradient, nsIDOMCanvasPattern, and nsIDOMTextMetrics (see [2-4]).

[1] https://developer.mozilla.org/en/Mozilla/WebIDL_bindings
[2] XPIDL: http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/canvas/nsIDOMCanvasRenderingContext2D.idl#16
[3] http://mxr.mozilla.org/mozilla-central/source/content/canvas/src/CanvasRenderingContext2D.h#38
[4] http://mxr.mozilla.org/mozilla-central/source/content/canvas/src/CanvasRenderingContext2D.cpp#159
Whiteboard: [good first bug][mentor=Ms2ger][lang=c++]
Version: 15 Branch → Trunk
I'm not sure how good-first-bug this one is, because it's not clear to me what to parent the objects to.  They're not tied to a particular canvas context, after all...

This is going to keep coming up a lot.  :(
I would like to work on this. But I am new to writing WebIDL interfaces, so I might need a bit help there.
Ms2ger and I are happy to help.  Please feel free to send mail or ping on IRC!
As I talked to Ms2ger on IRC, he said to implement CanvasPattern first from http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#canvaspattern

But I don't find any SVGMatrix type or class in http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/canvas/nsIDOMCanvasRenderingContext2D.idl . So is there any other substitute to SVGMatrix?
Nope.  Just comment out setTransform in the IDL: we don't implement it at the moment, and implementing it is not part of this bug at all.  ;)
Attached patch CanvasPattern WebIDL implementation (obsolete) (deleted) — Splinter Review
I just converted the CanvasPattern to WebIDL. Is there anything more to be done for CanvasPattern in the sources? Once the Canvaspattern class is done, I'll start off with the others.
Assignee: nobody → sankha93
Attachment #687673 - Flags: feedback?(bzbarsky)
Attachment #687673 - Flags: feedback?(Ms2ger)
You'll need to update the implementation class:

http://mxr.mozilla.org/mozilla-central/source/content/canvas/src/CanvasRenderingContext2D.h#89

to inherit from nsWrapperCache and add "SetIsDOMBinding()" to the constructor, for starters. See also <https://developer.mozilla.org/en-US/docs/Mozilla/WebIDL_bindings>.
Comment on attachment 687673 [details] [diff] [review]
CanvasPattern WebIDL implementation

Indeed.  I'm a little surprised this compiles, actually...  It's a good start, but the wrapper caching bits need to happen.

You might also need changes to the WrapStyle function in CanvasRenderingContext2D.cpp, and the GetStyleAsStringOrInterface bits.
Attachment #687673 - Flags: feedback?(bzbarsky) → feedback+
Attached patch WIP patch (obsolete) (deleted) — Splinter Review
This is a WIP patch. Sorry because of the weekend, I could not ask on IRC. I am getting build errors on this. The specific error can be found at http://pastebin.mozilla.org/1982236

Could you help me out with this?
Attachment #687673 - Attachment is obsolete: true
Attachment #687673 - Flags: feedback?(Ms2ger)
Attachment #690058 - Flags: feedback?(bzbarsky)
Attachment #690058 - Flags: feedback?(Ms2ger)
And adding the missing '; there might help too.  ;)
Attachment #690058 - Flags: feedback?(bzbarsky)
Comment on attachment 690058 [details] [diff] [review]
WIP patch

Review of attachment 690058 [details] [diff] [review]:
-----------------------------------------------------------------

::: content/canvas/src/CanvasRenderingContext2D.h
@@ +122,5 @@
>  
> +  virtual JSObject* WrapObject(JSContext *cx, JSObject *scope,
> +                               bool *triedToWrap)
> +  {
> +    return mozilla::dom::CanvasPatternBinding::WrapObject(cx, scope, this, triedToWrap)

Wrap, not WrapObject; and a ';' as bz mentioned.
Attachment #690058 - Flags: feedback?(Ms2ger)
Attached patch Does not compile (obsolete) (deleted) — Splinter Review
I made the changes, but still getting the CanvasPatternBinding not declared error.

 0:56.03 In file included from /home/sankha/oss/nightly/mozilla-central/content/canvas/src/CanvasRenderingContext2D.cpp:7:0:
 0:56.03 /home/sankha/oss/nightly/mozilla-central/content/canvas/src/CanvasRenderingContext2D.h: In member function ‘virtual JSObject* mozilla::dom::CanvasPattern::WrapObject(JSContext*, JSObject*, bool*)’:
 0:56.03 /home/sankha/oss/nightly/mozilla-central/content/canvas/src/CanvasRenderingContext2D.h:119:26: error: ‘mozilla::dom::CanvasPatternBinding’ has not been declared
 0:56.61 ../../../../dist/include/mozilla/dom/CanvasRenderingContext2D.h:120:3: error: control reaches end of non-void function [-Werror=return-type]

==================
I tried the step 7 in https://developer.mozilla.org/en-US/docs/Mozilla/WebIDL_bindings#Adding_WebIDL_bindings_to_a_class to generate CanvasPattern-example.cpp, which had CanvasPatternBinding declared. So I am unable to understand why does it say undeclared?
Attachment #690058 - Attachment is obsolete: true
Attachment #690125 - Flags: feedback?(bzbarsky)
Attachment #690125 - Flags: feedback?(Ms2ger)
You lost the following hunk from http://pastebin.mozilla.org/1982557 somewhere:

diff --git a/content/canvas/src/CanvasRenderingContext2D.h b/content/canvas/src/CanvasRenderingContext2D.h
--- a/content/canvas/src/CanvasRenderingContext2D.h
+++ b/content/canvas/src/CanvasRenderingContext2D.h
@@ -12,16 +12,17 @@
 #include "nsColor.h"
 #include "nsHTMLCanvasElement.h"
 #include "nsHTMLVideoElement.h"
 #include "CanvasUtils.h"
 #include "gfxFont.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/dom/ImageData.h"
 #include "mozilla/dom/UnionTypes.h"
+#include "mozilla/dom/CanvasPatternBinding.h"
 
 #define NS_CANVASGRADIENTAZURE_PRIVATE_IID \
     {0x28425a6a, 0x90e0, 0x4d42, {0x9c, 0x75, 0xff, 0x60, 0x09, 0xb3, 0x10, 0xa8}}
 #define NS_CANVASPATTERNAZURE_PRIVATE_IID \
     {0xc9bacc25, 0x28da, 0x421e, {0x9a, 0x4b, 0xbb, 0xd6, 0x93, 0x05, 0x12, 0xbc}}
 
 class nsIDOMXULElement;
Comment on attachment 690125 [details] [diff] [review]
Does not compile

What ms2ger said.
Attachment #690125 - Flags: feedback?(bzbarsky)
Attached patch Part 1: Moves CanvasPattern to WebIDL (obsolete) (deleted) — Splinter Review
This moves the CanvasPattern interface to WebIDL. Now I am beginning to work on TextMetrics.
Attachment #690125 - Attachment is obsolete: true
Attachment #690125 - Flags: feedback?(Ms2ger)
Attachment #691672 - Flags: review?(bzbarsky)
Attachment #691672 - Flags: review?(Ms2ger)
Patch after addressing bz's comments on IRC.
Attachment #691672 - Attachment is obsolete: true
Attachment #691672 - Flags: review?(bzbarsky)
Attachment #691672 - Flags: review?(Ms2ger)
Attachment #691773 - Flags: feedback?(bzbarsky)
Attachment #691773 - Flags: feedback?(Ms2ger)
Comment on attachment 691773 [details] [diff] [review]
Part 1: Moves CanvasPattern to WebIDL

That seems much more plausible.

Have you run the canvas tests?  Or at least manual fillStyle/strokeStyle tests?
Attachment #691773 - Flags: feedback?(bzbarsky) → feedback+
This patch tries to move TextMetrics interface to WebIDL, but it doesn't compile. The errors that I'm getting are here: http://pastebin.mozilla.org/2012105
Attachment #694914 - Flags: feedback?(Ms2ger)
Comment on attachment 694914 [details] [diff] [review]
Part 2: Moves TextMetrics to WebIDL

Review of attachment 694914 [details] [diff] [review]:
-----------------------------------------------------------------

I think you forgot to "hg add" the webidl file?

::: content/canvas/src/CanvasRenderingContext2D.h
@@ -263,5 @@
>    void StrokeText(const nsAString& text, double x, double y,
>                    const mozilla::dom::Optional<double>& maxWidth,
>                    mozilla::ErrorResult& error);
> -  already_AddRefed<nsIDOMTextMetrics>
> -    MeasureText(const nsAString& rawText, mozilla::ErrorResult& error);

This seems to have moved somewhere it shouldn't have
Attachment #691773 - Flags: feedback?(Ms2ger) → feedback+
Comment on attachment 694914 [details] [diff] [review]
Part 2: Moves TextMetrics to WebIDL

Review of attachment 694914 [details] [diff] [review]:
-----------------------------------------------------------------

Can you check if the issues I pointed out in comment 21 helps?
Attachment #694914 - Flags: feedback?(Ms2ger)
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → DUPLICATE
Whiteboard: [good first bug][mentor=Ms2ger][lang=c++]
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: