summaryrefslogtreecommitdiff
path: root/src/js/shape/mxStencilShape.js
blob: 9c95f8b6367e3824608a0f00c54cbc0e754ac916 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/**
 * $Id: mxStencilShape.js,v 1.10 2012-07-16 10:22:44 gaudenz Exp $
 * Copyright (c) 2006-2010, JGraph Ltd
 */
/**
 * Class: mxStencilShape
 *
 * Implements a shape based on a <mxStencil>.
 *  
 * Constructor: mxStencilShape
 * 
 * Constructs a new generic shape.
 */
function mxStencilShape(stencil)
{
	this.stencil = stencil;
};

/**
 * Extends mxShape.
 */
mxStencilShape.prototype = new mxShape();
mxStencilShape.prototype.constructor = mxStencilShape;

/**
 * Variable: mixedModeHtml
 *
 * Always prefers VML in mixed mode for stencil shapes. Default is false.
 */
mxStencilShape.prototype.mixedModeHtml = false;

/**
 * Variable: preferModeHtml
 *
 * Always prefers VML in prefer HTML mode for stencil shapes. Default is false.
 */
mxStencilShape.prototype.preferModeHtml = false;

/**
 * Variable: stencil
 *
 * Holds the <mxStencil> that defines the shape.
 */
mxStencilShape.prototype.stencil = null;

/**
 * Variable: state
 *
 * Holds the <mxCellState> associated with this shape.
 */
mxStencilShape.prototype.state = null;

/**
 * Variable: vmlScale
 *
 * Renders VML with a scale of 4.
 */
mxStencilShape.prototype.vmlScale = 4;

/**
 * Function: apply
 * 
 * Extends <mxShape> apply to keep a reference to the <mxCellState>.
 *
 * Parameters:
 *
 * state - <mxCellState> of the corresponding cell.
 */
mxStencilShape.prototype.apply = function(state)
{
	this.state = state;
	mxShape.prototype.apply.apply(this, arguments);
};

/**
 * Function: createSvg
 *
 * Creates and returns the SVG node(s) to represent this shape.
 */
mxStencilShape.prototype.createSvg = function()
{
	var node = document.createElementNS(mxConstants.NS_SVG, 'g');
	this.configureSvgShape(node);
	
	return node;
};

/**
 * Function: configureHtmlShape
 *
 * Overrides method to set the overflow style to visible.
 */
mxStencilShape.prototype.configureHtmlShape = function(node)
{
	mxShape.prototype.configureHtmlShape.apply(this, arguments);
	
	if (!mxUtils.isVml(node))
	{
		node.style.overflow = 'visible';
	}
};

/**
 * Function: createVml
 *
 * Creates and returns the VML node to represent this shape.
 */
mxStencilShape.prototype.createVml = function()
{
	var name = (document.documentMode == 8) ? 'div' : 'v:group';
	var node = document.createElement(name);
	this.configureTransparentBackground(node);
	node.style.position = 'absolute';
	
	return node;
};

/**
 * Function: configureVmlShape
 *
 * Configures the specified VML node by applying the current color,
 * bounds, shadow, opacity etc.
 */
mxStencilShape.prototype.configureVmlShape = function(node)
{
	// do nothing
};

/**
 * Function: redraw
 *
 * Creates and returns the SVG node(s) to represent this shape.
 */
mxStencilShape.prototype.redraw = function()
{
	this.updateBoundingBox();
	
	if (this.dialect == mxConstants.DIALECT_SVG)
	{
		this.redrawShape();
	}
	else
	{
		this.node.style.visibility = 'hidden';
		this.redrawShape();
		this.node.style.visibility = 'visible';
	}
};

/**
 * Function: redrawShape
 *
 * Updates the SVG or VML shape.
 */
mxStencilShape.prototype.redrawShape = function()
{
	// LATER: Update existing DOM nodes to improve repaint performance
	if (this.dialect != mxConstants.DIALECT_SVG)
	{
		this.node.style.left = Math.round(this.bounds.x) + 'px';
		this.node.style.top = Math.round(this.bounds.y) + 'px';
		var w = Math.round(this.bounds.width);
		var h = Math.round(this.bounds.height);
		this.node.style.width = w + 'px';
		this.node.style.height = h + 'px';
		
		var node = this.node;
		
		// Workaround for VML rendering bug in IE8 standards mode where all VML must be
		// parsed via assigning the innerHTML of the parent HTML node to keep all event
		// handlers referencing node and support rotation via v:group parent element. 
		if (this.node.nodeName == 'DIV')
		{
			node = document.createElement('v:group');
			node.style.position = 'absolute';
			node.style.left = '0px';
			node.style.top = '0px';
			node.style.width = w + 'px';
			node.style.height = h + 'px';
		}
		else
		{
			node.innerHTML = '';
		}

		if (mxUtils.isVml(node))
		{
			var s = (document.documentMode != 8) ? this.vmlScale : 1;
			node.coordsize = (w * s) + ',' + (h * s);
		}
		
		this.stencil.renderDom(this, this.bounds, node);
		
		if(this.node != node)
		{
			// Forces parsing in IE8 standards mode
			this.node.innerHTML = node.outerHTML;
		}
	}
	else
	{
		while (this.node.firstChild != null)
		{
			this.node.removeChild(this.node.firstChild);
		}
		
		this.stencil.renderDom(this, this.bounds, this.node);
	}
};