eads@18: // Copyright 2006 Google Inc. eads@18: // eads@18: // Licensed under the Apache License, Version 2.0 (the "License"); eads@18: // you may not use this file except in compliance with the License. eads@18: // You may obtain a copy of the License at eads@18: // eads@18: // http://www.apache.org/licenses/LICENSE-2.0 eads@18: // eads@18: // Unless required by applicable law or agreed to in writing, software eads@18: // distributed under the License is distributed on an "AS IS" BASIS, eads@18: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. eads@18: // See the License for the specific language governing permissions and eads@18: // limitations under the License. eads@18: eads@18: eads@18: // Known Issues: eads@18: // eads@18: // * Patterns are not implemented. eads@18: // * Radial gradient are not implemented. The VML version of these look very eads@18: // different from the canvas one. eads@18: // * Clipping paths are not implemented. eads@18: // * Coordsize. The width and height attribute have higher priority than the eads@18: // width and height style values which isn't correct. eads@18: // * Painting mode isn't implemented. eads@18: // * Canvas width/height should is using content-box by default. IE in eads@18: // Quirks mode will draw the canvas using border-box. Either change your eads@18: // doctype to HTML5 eads@18: // (http://www.whatwg.org/specs/web-apps/current-work/#the-doctype) eads@18: // or use Box Sizing Behavior from WebFX eads@18: // (http://webfx.eae.net/dhtml/boxsizing/boxsizing.html) eads@18: // * Optimize. There is always room for speed improvements. eads@18: eads@18: // only add this code if we do not already have a canvas implementation eads@18: if (!window.CanvasRenderingContext2D) { eads@18: eads@18: (function () { eads@18: eads@18: // alias some functions to make (compiled) code shorter eads@18: var m = Math; eads@18: var mr = m.round; eads@18: var ms = m.sin; eads@18: var mc = m.cos; eads@18: eads@18: // this is used for sub pixel precision eads@18: var Z = 10; eads@18: var Z2 = Z / 2; eads@18: eads@18: var G_vmlCanvasManager_ = { eads@18: init: function (opt_doc) { eads@18: var doc = opt_doc || document; eads@18: if (/MSIE/.test(navigator.userAgent) && !window.opera) { eads@18: var self = this; eads@18: doc.attachEvent("onreadystatechange", function () { eads@18: self.init_(doc); eads@18: }); eads@18: } eads@18: }, eads@18: eads@18: init_: function (doc) { eads@18: if (doc.readyState == "complete") { eads@18: // create xmlns eads@18: if (!doc.namespaces["g_vml_"]) { eads@18: doc.namespaces.add("g_vml_", "urn:schemas-microsoft-com:vml"); eads@18: } eads@18: eads@18: // setup default css eads@18: var ss = doc.createStyleSheet(); eads@18: ss.cssText = "canvas{display:inline-block;overflow:hidden;" + eads@18: // default size is 300x150 in Gecko and Opera eads@18: "text-align:left;width:300px;height:150px}" + eads@18: "g_vml_\\:*{behavior:url(#default#VML)}"; eads@18: eads@18: // find all canvas elements eads@18: var els = doc.getElementsByTagName("canvas"); eads@18: for (var i = 0; i < els.length; i++) { eads@18: if (!els[i].getContext) { eads@18: this.initElement(els[i]); eads@18: } eads@18: } eads@18: } eads@18: }, eads@18: eads@18: fixElement_: function (el) { eads@18: // in IE before version 5.5 we would need to add HTML: to the tag name eads@18: // but we do not care about IE before version 6 eads@18: var outerHTML = el.outerHTML; eads@18: eads@18: var newEl = el.ownerDocument.createElement(outerHTML); eads@18: // if the tag is still open IE has created the children as siblings and eads@18: // it has also created a tag with the name "/FOO" eads@18: if (outerHTML.slice(-2) != "/>") { eads@18: var tagName = "/" + el.tagName; eads@18: var ns; eads@18: // remove content eads@18: while ((ns = el.nextSibling) && ns.tagName != tagName) { eads@18: ns.removeNode(); eads@18: } eads@18: // remove the incorrect closing tag eads@18: if (ns) { eads@18: ns.removeNode(); eads@18: } eads@18: } eads@18: el.parentNode.replaceChild(newEl, el); eads@18: return newEl; eads@18: }, eads@18: eads@18: /** eads@18: * Public initializes a canvas element so that it can be used as canvas eads@18: * element from now on. This is called automatically before the page is eads@18: * loaded but if you are creating elements using createElement you need to eads@18: * make sure this is called on the element. eads@18: * @param {HTMLElement} el The canvas element to initialize. eads@18: * @return {HTMLElement} the element that was created. eads@18: */ eads@18: initElement: function (el) { eads@18: el = this.fixElement_(el); eads@18: el.getContext = function () { eads@18: if (this.context_) { eads@18: return this.context_; eads@18: } eads@18: return this.context_ = new CanvasRenderingContext2D_(this); eads@18: }; eads@18: eads@18: // do not use inline function because that will leak memory eads@18: el.attachEvent('onpropertychange', onPropertyChange); eads@18: el.attachEvent('onresize', onResize); eads@18: eads@18: var attrs = el.attributes; eads@18: if (attrs.width && attrs.width.specified) { eads@18: // TODO: use runtimeStyle and coordsize eads@18: // el.getContext().setWidth_(attrs.width.nodeValue); eads@18: el.style.width = attrs.width.nodeValue + "px"; eads@18: } else { eads@18: el.width = el.clientWidth; eads@18: } eads@18: if (attrs.height && attrs.height.specified) { eads@18: // TODO: use runtimeStyle and coordsize eads@18: // el.getContext().setHeight_(attrs.height.nodeValue); eads@18: el.style.height = attrs.height.nodeValue + "px"; eads@18: } else { eads@18: el.height = el.clientHeight; eads@18: } eads@18: //el.getContext().setCoordsize_() eads@18: return el; eads@18: } eads@18: }; eads@18: eads@18: function onPropertyChange(e) { eads@18: var el = e.srcElement; eads@18: eads@18: switch (e.propertyName) { eads@18: case 'width': eads@18: el.style.width = el.attributes.width.nodeValue + "px"; eads@18: el.getContext().clearRect(); eads@18: break; eads@18: case 'height': eads@18: el.style.height = el.attributes.height.nodeValue + "px"; eads@18: el.getContext().clearRect(); eads@18: break; eads@18: } eads@18: } eads@18: eads@18: function onResize(e) { eads@18: var el = e.srcElement; eads@18: if (el.firstChild) { eads@18: el.firstChild.style.width = el.clientWidth + 'px'; eads@18: el.firstChild.style.height = el.clientHeight + 'px'; eads@18: } eads@18: } eads@18: eads@18: G_vmlCanvasManager_.init(); eads@18: eads@18: // precompute "00" to "FF" eads@18: var dec2hex = []; eads@18: for (var i = 0; i < 16; i++) { eads@18: for (var j = 0; j < 16; j++) { eads@18: dec2hex[i * 16 + j] = i.toString(16) + j.toString(16); eads@18: } eads@18: } eads@18: eads@18: function createMatrixIdentity() { eads@18: return [ eads@18: [1, 0, 0], eads@18: [0, 1, 0], eads@18: [0, 0, 1] eads@18: ]; eads@18: } eads@18: eads@18: function matrixMultiply(m1, m2) { eads@18: var result = createMatrixIdentity(); eads@18: eads@18: for (var x = 0; x < 3; x++) { eads@18: for (var y = 0; y < 3; y++) { eads@18: var sum = 0; eads@18: eads@18: for (var z = 0; z < 3; z++) { eads@18: sum += m1[x][z] * m2[z][y]; eads@18: } eads@18: eads@18: result[x][y] = sum; eads@18: } eads@18: } eads@18: return result; eads@18: } eads@18: eads@18: function copyState(o1, o2) { eads@18: o2.fillStyle = o1.fillStyle; eads@18: o2.lineCap = o1.lineCap; eads@18: o2.lineJoin = o1.lineJoin; eads@18: o2.lineWidth = o1.lineWidth; eads@18: o2.miterLimit = o1.miterLimit; eads@18: o2.shadowBlur = o1.shadowBlur; eads@18: o2.shadowColor = o1.shadowColor; eads@18: o2.shadowOffsetX = o1.shadowOffsetX; eads@18: o2.shadowOffsetY = o1.shadowOffsetY; eads@18: o2.strokeStyle = o1.strokeStyle; eads@18: o2.arcScaleX_ = o1.arcScaleX_; eads@18: o2.arcScaleY_ = o1.arcScaleY_; eads@18: } eads@18: eads@18: function processStyle(styleString) { eads@18: var str, alpha = 1; eads@18: eads@18: styleString = String(styleString); eads@18: if (styleString.substring(0, 3) == "rgb") { eads@18: var start = styleString.indexOf("(", 3); eads@18: var end = styleString.indexOf(")", start + 1); eads@18: var guts = styleString.substring(start + 1, end).split(","); eads@18: eads@18: str = "#"; eads@18: for (var i = 0; i < 3; i++) { eads@18: str += dec2hex[Number(guts[i])]; eads@18: } eads@18: eads@18: if ((guts.length == 4) && (styleString.substr(3, 1) == "a")) { eads@18: alpha = guts[3]; eads@18: } eads@18: } else { eads@18: str = styleString; eads@18: } eads@18: eads@18: return [str, alpha]; eads@18: } eads@18: eads@18: function processLineCap(lineCap) { eads@18: switch (lineCap) { eads@18: case "butt": eads@18: return "flat"; eads@18: case "round": eads@18: return "round"; eads@18: case "square": eads@18: default: eads@18: return "square"; eads@18: } eads@18: } eads@18: eads@18: /** eads@18: * This class implements CanvasRenderingContext2D interface as described by eads@18: * the WHATWG. eads@18: * @param {HTMLElement} surfaceElement The element that the 2D context should eads@18: * be associated with eads@18: */ eads@18: function CanvasRenderingContext2D_(surfaceElement) { eads@18: this.m_ = createMatrixIdentity(); eads@18: eads@18: this.mStack_ = []; eads@18: this.aStack_ = []; eads@18: this.currentPath_ = []; eads@18: eads@18: // Canvas context properties eads@18: this.strokeStyle = "#000"; eads@18: this.fillStyle = "#000"; eads@18: eads@18: this.lineWidth = 1; eads@18: this.lineJoin = "miter"; eads@18: this.lineCap = "butt"; eads@18: this.miterLimit = Z * 1; eads@18: this.globalAlpha = 1; eads@18: this.canvas = surfaceElement; eads@18: eads@18: var el = surfaceElement.ownerDocument.createElement('div'); eads@18: el.style.width = surfaceElement.clientWidth + 'px'; eads@18: el.style.height = surfaceElement.clientHeight + 'px'; eads@18: el.style.overflow = 'hidden'; eads@18: el.style.position = 'absolute'; eads@18: surfaceElement.appendChild(el); eads@18: eads@18: this.element_ = el; eads@18: this.arcScaleX_ = 1; eads@18: this.arcScaleY_ = 1; eads@18: }; eads@18: eads@18: var contextPrototype = CanvasRenderingContext2D_.prototype; eads@18: contextPrototype.clearRect = function() { eads@18: this.element_.innerHTML = ""; eads@18: this.currentPath_ = []; eads@18: }; eads@18: eads@18: contextPrototype.beginPath = function() { eads@18: // TODO: Branch current matrix so that save/restore has no effect eads@18: // as per safari docs. eads@18: eads@18: this.currentPath_ = []; eads@18: }; eads@18: eads@18: contextPrototype.moveTo = function(aX, aY) { eads@18: this.currentPath_.push({type: "moveTo", x: aX, y: aY}); eads@18: this.currentX_ = aX; eads@18: this.currentY_ = aY; eads@18: }; eads@18: eads@18: contextPrototype.lineTo = function(aX, aY) { eads@18: this.currentPath_.push({type: "lineTo", x: aX, y: aY}); eads@18: this.currentX_ = aX; eads@18: this.currentY_ = aY; eads@18: }; eads@18: eads@18: contextPrototype.bezierCurveTo = function(aCP1x, aCP1y, eads@18: aCP2x, aCP2y, eads@18: aX, aY) { eads@18: this.currentPath_.push({type: "bezierCurveTo", eads@18: cp1x: aCP1x, eads@18: cp1y: aCP1y, eads@18: cp2x: aCP2x, eads@18: cp2y: aCP2y, eads@18: x: aX, eads@18: y: aY}); eads@18: this.currentX_ = aX; eads@18: this.currentY_ = aY; eads@18: }; eads@18: eads@18: contextPrototype.quadraticCurveTo = function(aCPx, aCPy, aX, aY) { eads@18: // the following is lifted almost directly from eads@18: // http://developer.mozilla.org/en/docs/Canvas_tutorial:Drawing_shapes eads@18: var cp1x = this.currentX_ + 2.0 / 3.0 * (aCPx - this.currentX_); eads@18: var cp1y = this.currentY_ + 2.0 / 3.0 * (aCPy - this.currentY_); eads@18: var cp2x = cp1x + (aX - this.currentX_) / 3.0; eads@18: var cp2y = cp1y + (aY - this.currentY_) / 3.0; eads@18: this.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, aX, aY); eads@18: }; eads@18: eads@18: contextPrototype.arc = function(aX, aY, aRadius, eads@18: aStartAngle, aEndAngle, aClockwise) { eads@18: aRadius *= Z; eads@18: var arcType = aClockwise ? "at" : "wa"; eads@18: eads@18: var xStart = aX + (mc(aStartAngle) * aRadius) - Z2; eads@18: var yStart = aY + (ms(aStartAngle) * aRadius) - Z2; eads@18: eads@18: var xEnd = aX + (mc(aEndAngle) * aRadius) - Z2; eads@18: var yEnd = aY + (ms(aEndAngle) * aRadius) - Z2; eads@18: eads@18: // IE won't render arches drawn counter clockwise if xStart == xEnd. eads@18: if (xStart == xEnd && !aClockwise) { eads@18: xStart += 0.125; // Offset xStart by 1/80 of a pixel. Use something eads@18: // that can be represented in binary eads@18: } eads@18: eads@18: this.currentPath_.push({type: arcType, eads@18: x: aX, eads@18: y: aY, eads@18: radius: aRadius, eads@18: xStart: xStart, eads@18: yStart: yStart, eads@18: xEnd: xEnd, eads@18: yEnd: yEnd}); eads@18: eads@18: }; eads@18: eads@18: contextPrototype.rect = function(aX, aY, aWidth, aHeight) { eads@18: this.moveTo(aX, aY); eads@18: this.lineTo(aX + aWidth, aY); eads@18: this.lineTo(aX + aWidth, aY + aHeight); eads@18: this.lineTo(aX, aY + aHeight); eads@18: this.closePath(); eads@18: }; eads@18: eads@18: contextPrototype.strokeRect = function(aX, aY, aWidth, aHeight) { eads@18: // Will destroy any existing path (same as FF behaviour) eads@18: this.beginPath(); eads@18: this.moveTo(aX, aY); eads@18: this.lineTo(aX + aWidth, aY); eads@18: this.lineTo(aX + aWidth, aY + aHeight); eads@18: this.lineTo(aX, aY + aHeight); eads@18: this.closePath(); eads@18: this.stroke(); eads@18: }; eads@18: eads@18: contextPrototype.fillRect = function(aX, aY, aWidth, aHeight) { eads@18: // Will destroy any existing path (same as FF behaviour) eads@18: this.beginPath(); eads@18: this.moveTo(aX, aY); eads@18: this.lineTo(aX + aWidth, aY); eads@18: this.lineTo(aX + aWidth, aY + aHeight); eads@18: this.lineTo(aX, aY + aHeight); eads@18: this.closePath(); eads@18: this.fill(); eads@18: }; eads@18: eads@18: contextPrototype.createLinearGradient = function(aX0, aY0, aX1, aY1) { eads@18: var gradient = new CanvasGradient_("gradient"); eads@18: return gradient; eads@18: }; eads@18: eads@18: contextPrototype.createRadialGradient = function(aX0, aY0, eads@18: aR0, aX1, eads@18: aY1, aR1) { eads@18: var gradient = new CanvasGradient_("gradientradial"); eads@18: gradient.radius1_ = aR0; eads@18: gradient.radius2_ = aR1; eads@18: gradient.focus_.x = aX0; eads@18: gradient.focus_.y = aY0; eads@18: return gradient; eads@18: }; eads@18: eads@18: contextPrototype.drawImage = function (image, var_args) { eads@18: var dx, dy, dw, dh, sx, sy, sw, sh; eads@18: eads@18: // to find the original width we overide the width and height eads@18: var oldRuntimeWidth = image.runtimeStyle.width; eads@18: var oldRuntimeHeight = image.runtimeStyle.height; eads@18: image.runtimeStyle.width = 'auto'; eads@18: image.runtimeStyle.height = 'auto'; eads@18: eads@18: // get the original size eads@18: var w = image.width; eads@18: var h = image.height; eads@18: eads@18: // and remove overides eads@18: image.runtimeStyle.width = oldRuntimeWidth; eads@18: image.runtimeStyle.height = oldRuntimeHeight; eads@18: eads@18: if (arguments.length == 3) { eads@18: dx = arguments[1]; eads@18: dy = arguments[2]; eads@18: sx = sy = 0; eads@18: sw = dw = w; eads@18: sh = dh = h; eads@18: } else if (arguments.length == 5) { eads@18: dx = arguments[1]; eads@18: dy = arguments[2]; eads@18: dw = arguments[3]; eads@18: dh = arguments[4]; eads@18: sx = sy = 0; eads@18: sw = w; eads@18: sh = h; eads@18: } else if (arguments.length == 9) { eads@18: sx = arguments[1]; eads@18: sy = arguments[2]; eads@18: sw = arguments[3]; eads@18: sh = arguments[4]; eads@18: dx = arguments[5]; eads@18: dy = arguments[6]; eads@18: dw = arguments[7]; eads@18: dh = arguments[8]; eads@18: } else { eads@18: throw "Invalid number of arguments"; eads@18: } eads@18: eads@18: var d = this.getCoords_(dx, dy); eads@18: eads@18: var w2 = sw / 2; eads@18: var h2 = sh / 2; eads@18: eads@18: var vmlStr = []; eads@18: eads@18: var W = 10; eads@18: var H = 10; eads@18: eads@18: // For some reason that I've now forgotten, using divs didn't work eads@18: vmlStr.push(' ' , eads@18: '', eads@18: ''); eads@18: eads@18: this.element_.insertAdjacentHTML("BeforeEnd", eads@18: vmlStr.join("")); eads@18: }; eads@18: eads@18: contextPrototype.stroke = function(aFill) { eads@18: var lineStr = []; eads@18: var lineOpen = false; eads@18: var a = processStyle(aFill ? this.fillStyle : this.strokeStyle); eads@18: var color = a[0]; eads@18: var opacity = a[1] * this.globalAlpha; eads@18: eads@18: var W = 10; eads@18: var H = 10; eads@18: eads@18: lineStr.push(' max.x) { eads@18: max.x = c.x; eads@18: } eads@18: if (min.y == null || c.y < min.y) { eads@18: min.y = c.y; eads@18: } eads@18: if (max.y == null || c.y > max.y) { eads@18: max.y = c.y; eads@18: } eads@18: } eads@18: } eads@18: lineStr.push(' ">'); eads@18: eads@18: if (typeof this.fillStyle == "object") { eads@18: var focus = {x: "50%", y: "50%"}; eads@18: var width = (max.x - min.x); eads@18: var height = (max.y - min.y); eads@18: var dimension = (width > height) ? width : height; eads@18: eads@18: focus.x = mr((this.fillStyle.focus_.x / width) * 100 + 50) + "%"; eads@18: focus.y = mr((this.fillStyle.focus_.y / height) * 100 + 50) + "%"; eads@18: eads@18: var colors = []; eads@18: eads@18: // inside radius (%) eads@18: if (this.fillStyle.type_ == "gradientradial") { eads@18: var inside = (this.fillStyle.radius1_ / dimension * 100); eads@18: eads@18: // percentage that outside radius exceeds inside radius eads@18: var expansion = (this.fillStyle.radius2_ / dimension * 100) - inside; eads@18: } else { eads@18: var inside = 0; eads@18: var expansion = 100; eads@18: } eads@18: eads@18: var insidecolor = {offset: null, color: null}; eads@18: var outsidecolor = {offset: null, color: null}; eads@18: eads@18: // We need to sort 'colors' by percentage, from 0 > 100 otherwise ie eads@18: // won't interpret it correctly eads@18: this.fillStyle.colors_.sort(function (cs1, cs2) { eads@18: return cs1.offset - cs2.offset; eads@18: }); eads@18: eads@18: for (var i = 0; i < this.fillStyle.colors_.length; i++) { eads@18: var fs = this.fillStyle.colors_[i]; eads@18: eads@18: colors.push( (fs.offset * expansion) + inside, "% ", fs.color, ","); eads@18: eads@18: if (fs.offset > insidecolor.offset || insidecolor.offset == null) { eads@18: insidecolor.offset = fs.offset; eads@18: insidecolor.color = fs.color; eads@18: } eads@18: eads@18: if (fs.offset < outsidecolor.offset || outsidecolor.offset == null) { eads@18: outsidecolor.offset = fs.offset; eads@18: outsidecolor.color = fs.color; eads@18: } eads@18: } eads@18: colors.pop(); eads@18: eads@18: lineStr.push(''); eads@18: } else if (aFill) { eads@18: lineStr.push(''); eads@18: } else { eads@18: lineStr.push( eads@18: '' eads@18: ); eads@18: } eads@18: eads@18: lineStr.push(""); eads@18: eads@18: this.element_.insertAdjacentHTML("beforeEnd", lineStr.join("")); eads@18: eads@18: this.currentPath_ = []; eads@18: }; eads@18: eads@18: contextPrototype.fill = function() { eads@18: this.stroke(true); eads@18: } eads@18: eads@18: contextPrototype.closePath = function() { eads@18: this.currentPath_.push({type: "close"}); eads@18: }; eads@18: eads@18: /** eads@18: * @private eads@18: */ eads@18: contextPrototype.getCoords_ = function(aX, aY) { eads@18: return { eads@18: x: Z * (aX * this.m_[0][0] + aY * this.m_[1][0] + this.m_[2][0]) - Z2, eads@18: y: Z * (aX * this.m_[0][1] + aY * this.m_[1][1] + this.m_[2][1]) - Z2 eads@18: } eads@18: }; eads@18: eads@18: contextPrototype.save = function() { eads@18: var o = {}; eads@18: copyState(this, o); eads@18: this.aStack_.push(o); eads@18: this.mStack_.push(this.m_); eads@18: this.m_ = matrixMultiply(createMatrixIdentity(), this.m_); eads@18: }; eads@18: eads@18: contextPrototype.restore = function() { eads@18: copyState(this.aStack_.pop(), this); eads@18: this.m_ = this.mStack_.pop(); eads@18: }; eads@18: eads@18: contextPrototype.translate = function(aX, aY) { eads@18: var m1 = [ eads@18: [1, 0, 0], eads@18: [0, 1, 0], eads@18: [aX, aY, 1] eads@18: ]; eads@18: eads@18: this.m_ = matrixMultiply(m1, this.m_); eads@18: }; eads@18: eads@18: contextPrototype.rotate = function(aRot) { eads@18: var c = mc(aRot); eads@18: var s = ms(aRot); eads@18: eads@18: var m1 = [ eads@18: [c, s, 0], eads@18: [-s, c, 0], eads@18: [0, 0, 1] eads@18: ]; eads@18: eads@18: this.m_ = matrixMultiply(m1, this.m_); eads@18: }; eads@18: eads@18: contextPrototype.scale = function(aX, aY) { eads@18: this.arcScaleX_ *= aX; eads@18: this.arcScaleY_ *= aY; eads@18: var m1 = [ eads@18: [aX, 0, 0], eads@18: [0, aY, 0], eads@18: [0, 0, 1] eads@18: ]; eads@18: eads@18: this.m_ = matrixMultiply(m1, this.m_); eads@18: }; eads@18: eads@18: /******** STUBS ********/ eads@18: contextPrototype.clip = function() { eads@18: // TODO: Implement eads@18: }; eads@18: eads@18: contextPrototype.arcTo = function() { eads@18: // TODO: Implement eads@18: }; eads@18: eads@18: contextPrototype.createPattern = function() { eads@18: return new CanvasPattern_; eads@18: }; eads@18: eads@18: // Gradient / Pattern Stubs eads@18: function CanvasGradient_(aType) { eads@18: this.type_ = aType; eads@18: this.radius1_ = 0; eads@18: this.radius2_ = 0; eads@18: this.colors_ = []; eads@18: this.focus_ = {x: 0, y: 0}; eads@18: } eads@18: eads@18: CanvasGradient_.prototype.addColorStop = function(aOffset, aColor) { eads@18: aColor = processStyle(aColor); eads@18: this.colors_.push({offset: 1-aOffset, color: aColor}); eads@18: }; eads@18: eads@18: function CanvasPattern_() {} eads@18: eads@18: // set up externs eads@18: G_vmlCanvasManager = G_vmlCanvasManager_; eads@18: CanvasRenderingContext2D = CanvasRenderingContext2D_; eads@18: CanvasGradient = CanvasGradient_; eads@18: CanvasPattern = CanvasPattern_; eads@18: eads@18: })(); eads@18: eads@18: } // if