2 * Copyright 2014 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #ifndef SkV8Example_JsContext_DEFINED
11 #define SkV8Example_JsContext_DEFINED
16 #include "DrawingMethods.h"
21 // Provides the canvas context implementation in JS, and the OnDraw() method in
22 // C++ that's used to bridge from C++ to JS. Should be used in JS as:
24 // function onDraw(context) {
25 // context.fillStyle="#FF0000";
26 // context.fillRect(x, y, w, h);
28 class JsContext : public DrawingMethods {
30 JsContext(Global* global)
35 virtual ~JsContext() {}
40 // Call this with the SkCanvas you want onDraw to draw on.
41 void onDraw(SkCanvas* canvas);
43 virtual SkCanvas* getCanvas() { return fCanvas; };
47 // Wrap the 'this' pointer into an Object. Can be retrieved via Unwrap.
48 v8::Handle<v8::Object> wrap();
50 // A handle to the onDraw function defined in the script.
51 v8::Persistent<v8::Function> fOnDraw;
53 // The template for what a canvas context object looks like. The canvas
54 // context object is what's passed into the JS onDraw() function.
55 static v8::Persistent<v8::ObjectTemplate> gContextTemplate;
57 // Only valid when inside OnDraw().
60 typedef DrawingMethods INHERITED;