| 1 |
/* |
| 2 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 |
* contributor license agreements. See the NOTICE file distributed with |
| 4 |
* this work for additional information regarding copyright ownership. |
| 5 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 |
* (the "License"); you may not use this file except in compliance with |
| 7 |
* the License. You may obtain a copy of the License at |
| 8 |
* |
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 11 |
* Unless required by applicable law or agreed to in writing, software |
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
* See the License for the specific language governing permissions and |
| 15 |
* limitations under the License. |
| 16 |
*/ |
| 17 |
|
| 18 |
function screenCTM(elem) { |
| 19 |
if (elem.getScreenCTM) |
| 20 |
return elem.getScreenCTM(); |
| 21 |
|
| 22 |
// This is to handle ASV 3.0, this depends on |
| 23 |
// a number of bugs in the ASV implementation. |
| 24 |
if (elem.currentScale) { |
| 25 |
var scale = root.currentScale; |
| 26 |
var trans = root.currentTranslate; |
| 27 |
var ret = root.createSVGMatrix(); |
| 28 |
ret.scale(scale); |
| 29 |
ret.translate(trans.x, trans.y); |
| 30 |
return ret; |
| 31 |
} |
| 32 |
|
| 33 |
var pMat = screenCTM(elem.parentNode); |
| 34 |
|
| 35 |
var eMat = elem.getCTM(); |
| 36 |
if (eMat == null) return pMat; |
| 37 |
eMat = eMat.multiply(pMat); |
| 38 |
return eMat; |
| 39 |
} |
| 40 |
|
| 41 |
function transformToElement(from, to) { |
| 42 |
if (!from.getTransformToElement) |
| 43 |
return from.getTransformToElement(to); |
| 44 |
var m1 = screenCTM(from); |
| 45 |
var m2 = screenCTM(to); |
| 46 |
return m1.multiply(m2.inverse()); |
| 47 |
} |
| 48 |
|
| 49 |
// Transform screen x/y to elem's coordinate system. |
| 50 |
// returns an SVGPoint object. |
| 51 |
function localPt(elem, x, y) { |
| 52 |
var mat = screenCTM(elem); |
| 53 |
var imat = mat.inverse(); |
| 54 |
var cPt = document.getRootElement().createSVGPoint(); |
| 55 |
cPt.x = x; |
| 56 |
cPt.y = y; |
| 57 |
cPt = cPt.matrixTransform(imat); |
| 58 |
return cPt; |
| 59 |
} |
| 60 |
|
| 61 |
function ForwardMouseDown(obj) { |
| 62 |
this.obj = obj; |
| 63 |
this.handleEvent = function(evt) { |
| 64 |
obj.mousedown(evt); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
function ForwardMouseMove(obj) { |
| 69 |
this.obj = obj; |
| 70 |
this.handleEvent = function(evt) { |
| 71 |
obj.mousemove(evt); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
function ForwardMouseUp(obj) { |
| 76 |
this.obj = obj; |
| 77 |
this.handleEvent = function(evt) { |
| 78 |
obj.mouseup(evt); |
| 79 |
} |
| 80 |
} |
| 81 |
|