Path: blob/trunk/third_party/closure/goog/graphics/vmlelement.js
2868 views
// Copyright 2007 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.131415/**16* @fileoverview Thin wrappers around the DOM element returned from17* the different draw methods of the graphics. This is the VML implementation.18* @author [email protected] (Erik Arvidsson)19*/2021goog.provide('goog.graphics.VmlEllipseElement');22goog.provide('goog.graphics.VmlGroupElement');23goog.provide('goog.graphics.VmlImageElement');24goog.provide('goog.graphics.VmlPathElement');25goog.provide('goog.graphics.VmlRectElement');26goog.provide('goog.graphics.VmlTextElement');272829goog.require('goog.dom');30goog.require('goog.graphics.EllipseElement');31goog.require('goog.graphics.GroupElement');32goog.require('goog.graphics.ImageElement');33goog.require('goog.graphics.PathElement');34goog.require('goog.graphics.RectElement');35goog.require('goog.graphics.TextElement');363738/**39* Returns the VML element corresponding to this object. This method is added40* to several classes below. Note that the return value of this method may41* change frequently in IE8, so it should not be cached externally.42* @return {Element} The VML element corresponding to this object.43* @this {goog.graphics.VmlGroupElement|goog.graphics.VmlEllipseElement|44* goog.graphics.VmlRectElement|goog.graphics.VmlPathElement|45* goog.graphics.VmlTextElement|goog.graphics.VmlImageElement}46* @private47*/48goog.graphics.vmlGetElement_ = function() {49this.element_ = this.getGraphics().getVmlElement(this.id_) || this.element_;50return this.element_;51};52535455/**56* Thin wrapper for VML group elements.57* This is an implementation of the goog.graphics.GroupElement interface.58* You should not construct objects from this constructor. The graphics59* will return the object for you.60* @param {Element} element The DOM element to wrap.61* @param {goog.graphics.VmlGraphics} graphics The graphics creating62* this element.63* @constructor64* @extends {goog.graphics.GroupElement}65* @deprecated goog.graphics is deprecated. It existed to abstract over browser66* differences before the canvas tag was widely supported. See67* http://en.wikipedia.org/wiki/Canvas_element for details.68* @final69*/70goog.graphics.VmlGroupElement = function(element, graphics) {71this.id_ = element.id;72goog.graphics.GroupElement.call(this, element, graphics);73};74goog.inherits(goog.graphics.VmlGroupElement, goog.graphics.GroupElement);757677/** @override */78goog.graphics.VmlGroupElement.prototype.getElement =79goog.graphics.vmlGetElement_;808182/**83* Remove all drawing elements from the group.84* @override85*/86goog.graphics.VmlGroupElement.prototype.clear = function() {87goog.dom.removeChildren(this.getElement());88};899091/**92* @return {boolean} True if this group is the root canvas element.93* @private94*/95goog.graphics.VmlGroupElement.prototype.isRootElement_ = function() {96return this.getGraphics().getCanvasElement() == this;97};9899100/**101* Set the size of the group element.102* @param {number|string} width The width of the group element.103* @param {number|string} height The height of the group element.104* @override105* @suppress {missingRequire} goog.graphics.VmlGraphics106*/107goog.graphics.VmlGroupElement.prototype.setSize = function(width, height) {108var element = this.getElement();109110var style = element.style;111style.width = goog.graphics.VmlGraphics.toSizePx(width);112style.height = goog.graphics.VmlGraphics.toSizePx(height);113114element.coordsize = goog.graphics.VmlGraphics.toSizeCoord(width) + ' ' +115goog.graphics.VmlGraphics.toSizeCoord(height);116117// Don't overwrite the root element's origin.118if (!this.isRootElement_()) {119element.coordorigin = '0 0';120}121};122123124125/**126* Thin wrapper for VML ellipse elements.127* This is an implementation of the goog.graphics.EllipseElement interface.128* You should not construct objects from this constructor. The graphics129* will return the object for you.130* @param {Element} element The DOM element to wrap.131* @param {goog.graphics.VmlGraphics} graphics The graphics creating132* this element.133* @param {number} cx Center X coordinate.134* @param {number} cy Center Y coordinate.135* @param {number} rx Radius length for the x-axis.136* @param {number} ry Radius length for the y-axis.137* @param {goog.graphics.Stroke?} stroke The stroke to use for this element.138* @param {goog.graphics.Fill?} fill The fill to use for this element.139* @constructor140* @extends {goog.graphics.EllipseElement}141* @deprecated goog.graphics is deprecated. It existed to abstract over browser142* differences before the canvas tag was widely supported. See143* http://en.wikipedia.org/wiki/Canvas_element for details.144* @final145*/146goog.graphics.VmlEllipseElement = function(147element, graphics, cx, cy, rx, ry, stroke, fill) {148this.id_ = element.id;149150goog.graphics.EllipseElement.call(this, element, graphics, stroke, fill);151152// Store center and radius for future calls to setRadius or setCenter.153154/**155* X coordinate of the ellipse center.156* @type {number}157*/158this.cx = cx;159160161/**162* Y coordinate of the ellipse center.163* @type {number}164*/165this.cy = cy;166167168/**169* Radius length for the x-axis.170* @type {number}171*/172this.rx = rx;173174175/**176* Radius length for the y-axis.177* @type {number}178*/179this.ry = ry;180};181goog.inherits(goog.graphics.VmlEllipseElement, goog.graphics.EllipseElement);182183184/** @override */185goog.graphics.VmlEllipseElement.prototype.getElement =186goog.graphics.vmlGetElement_;187188189/**190* Update the center point of the ellipse.191* @param {number} cx Center X coordinate.192* @param {number} cy Center Y coordinate.193* @override194*/195goog.graphics.VmlEllipseElement.prototype.setCenter = function(cx, cy) {196this.cx = cx;197this.cy = cy;198/** @suppress {missingRequire} */199goog.graphics.VmlGraphics.setPositionAndSize(200this.getElement(), cx - this.rx, cy - this.ry, this.rx * 2, this.ry * 2);201};202203204/**205* Update the radius of the ellipse.206* @param {number} rx Center X coordinate.207* @param {number} ry Center Y coordinate.208* @override209*/210goog.graphics.VmlEllipseElement.prototype.setRadius = function(rx, ry) {211this.rx = rx;212this.ry = ry;213/** @suppress {missingRequire} */214goog.graphics.VmlGraphics.setPositionAndSize(215this.getElement(), this.cx - rx, this.cy - ry, rx * 2, ry * 2);216};217218219220/**221* Thin wrapper for VML rectangle elements.222* This is an implementation of the goog.graphics.RectElement interface.223* You should not construct objects from this constructor. The graphics224* will return the object for you.225* @param {Element} element The DOM element to wrap.226* @param {goog.graphics.VmlGraphics} graphics The graphics creating227* this element.228* @param {goog.graphics.Stroke?} stroke The stroke to use for this element.229* @param {goog.graphics.Fill?} fill The fill to use for this element.230* @constructor231* @extends {goog.graphics.RectElement}232* @deprecated goog.graphics is deprecated. It existed to abstract over browser233* differences before the canvas tag was widely supported. See234* http://en.wikipedia.org/wiki/Canvas_element for details.235* @final236*/237goog.graphics.VmlRectElement = function(element, graphics, stroke, fill) {238this.id_ = element.id;239goog.graphics.RectElement.call(this, element, graphics, stroke, fill);240};241goog.inherits(goog.graphics.VmlRectElement, goog.graphics.RectElement);242243244/** @override */245goog.graphics.VmlRectElement.prototype.getElement =246goog.graphics.vmlGetElement_;247248249/**250* Update the position of the rectangle.251* @param {number} x X coordinate (left).252* @param {number} y Y coordinate (top).253* @override254*/255goog.graphics.VmlRectElement.prototype.setPosition = function(x, y) {256var style = this.getElement().style;257258style.left = /** @suppress {missingRequire} */259goog.graphics.VmlGraphics.toPosPx(x);260style.top = /** @suppress {missingRequire} */261goog.graphics.VmlGraphics.toPosPx(y);262};263264265/**266* Update the size of the rectangle.267* @param {number} width Width of rectangle.268* @param {number} height Height of rectangle.269* @override270* @suppress {missingRequire} goog.graphics.VmlGraphics271*/272goog.graphics.VmlRectElement.prototype.setSize = function(width, height) {273var style = this.getElement().style;274style.width = goog.graphics.VmlGraphics.toSizePx(width);275style.height = goog.graphics.VmlGraphics.toSizePx(height);276};277278279280/**281* Thin wrapper for VML path elements.282* This is an implementation of the goog.graphics.PathElement interface.283* You should not construct objects from this constructor. The graphics284* will return the object for you.285* @param {Element} element The DOM element to wrap.286* @param {goog.graphics.VmlGraphics} graphics The graphics creating287* this element.288* @param {goog.graphics.Stroke?} stroke The stroke to use for this element.289* @param {goog.graphics.Fill?} fill The fill to use for this element.290* @constructor291* @extends {goog.graphics.PathElement}292* @deprecated goog.graphics is deprecated. It existed to abstract over browser293* differences before the canvas tag was widely supported. See294* http://en.wikipedia.org/wiki/Canvas_element for details.295* @final296*/297goog.graphics.VmlPathElement = function(element, graphics, stroke, fill) {298this.id_ = element.id;299goog.graphics.PathElement.call(this, element, graphics, stroke, fill);300};301goog.inherits(goog.graphics.VmlPathElement, goog.graphics.PathElement);302303304/** @override */305goog.graphics.VmlPathElement.prototype.getElement =306goog.graphics.vmlGetElement_;307308309/**310* Update the underlying path.311* @param {!goog.graphics.Path} path The path object to draw.312* @override313*/314goog.graphics.VmlPathElement.prototype.setPath = function(path) {315/** @suppress {missingRequire} */316goog.graphics.VmlGraphics.setAttribute(317this.getElement(), 'path',318/** @suppress {missingRequire} */319goog.graphics.VmlGraphics.getVmlPath(path));320};321322323324/**325* Thin wrapper for VML text elements.326* This is an implementation of the goog.graphics.TextElement interface.327* You should not construct objects from this constructor. The graphics328* will return the object for you.329* @param {Element} element The DOM element to wrap.330* @param {goog.graphics.VmlGraphics} graphics The graphics creating331* this element.332* @param {goog.graphics.Stroke?} stroke The stroke to use for this element.333* @param {goog.graphics.Fill?} fill The fill to use for this element.334* @constructor335* @extends {goog.graphics.TextElement}336* @deprecated goog.graphics is deprecated. It existed to abstract over browser337* differences before the canvas tag was widely supported. See338* http://en.wikipedia.org/wiki/Canvas_element for details.339* @final340*/341goog.graphics.VmlTextElement = function(element, graphics, stroke, fill) {342this.id_ = element.id;343goog.graphics.TextElement.call(this, element, graphics, stroke, fill);344};345goog.inherits(goog.graphics.VmlTextElement, goog.graphics.TextElement);346347348/** @override */349goog.graphics.VmlTextElement.prototype.getElement =350goog.graphics.vmlGetElement_;351352353/**354* Update the displayed text of the element.355* @param {string} text The text to draw.356* @override357*/358goog.graphics.VmlTextElement.prototype.setText = function(text) {359/** @suppress {missingRequire} */360goog.graphics.VmlGraphics.setAttribute(361/** @type {!Element} */ (this.getElement().childNodes[1]), 'string',362text);363};364365366367/**368* Thin wrapper for VML image elements.369* This is an implementation of the goog.graphics.ImageElement interface.370* You should not construct objects from this constructor. The graphics371* will return the object for you.372* @param {Element} element The DOM element to wrap.373* @param {goog.graphics.VmlGraphics} graphics The graphics creating374* this element.375* @constructor376* @extends {goog.graphics.ImageElement}377* @deprecated goog.graphics is deprecated. It existed to abstract over browser378* differences before the canvas tag was widely supported. See379* http://en.wikipedia.org/wiki/Canvas_element for details.380* @final381*/382goog.graphics.VmlImageElement = function(element, graphics) {383this.id_ = element.id;384goog.graphics.ImageElement.call(this, element, graphics);385};386goog.inherits(goog.graphics.VmlImageElement, goog.graphics.ImageElement);387388389/** @override */390goog.graphics.VmlImageElement.prototype.getElement =391goog.graphics.vmlGetElement_;392393394/**395* Update the position of the image.396* @param {number} x X coordinate (left).397* @param {number} y Y coordinate (top).398* @override399*/400goog.graphics.VmlImageElement.prototype.setPosition = function(x, y) {401var style = this.getElement().style;402403style.left = /** @suppress {missingRequire} */404goog.graphics.VmlGraphics.toPosPx(x);405style.top = /** @suppress {missingRequire} */406goog.graphics.VmlGraphics.toPosPx(y);407};408409410/**411* Update the size of the image.412* @param {number} width Width of rectangle.413* @param {number} height Height of rectangle.414* @override415* @suppress {missingRequire} goog.graphics.VmlGraphics416*/417goog.graphics.VmlImageElement.prototype.setSize = function(width, height) {418var style = this.getElement().style;419style.width = goog.graphics.VmlGraphics.toPosPx(width);420style.height = goog.graphics.VmlGraphics.toPosPx(height);421};422423424/**425* Update the source of the image.426* @param {string} src Source of the image.427* @override428*/429goog.graphics.VmlImageElement.prototype.setSource = function(src) {430/** @suppress {missingRequire} */431goog.graphics.VmlGraphics.setAttribute(this.getElement(), 'src', src);432};433434435