aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D/view-utils.js
diff options
context:
space:
mode:
authorJohn Mayhew2012-07-24 15:46:16 -0700
committerJohn Mayhew2012-07-24 15:46:16 -0700
commit9f240b8b9b1f5fb0f145c343ca5e533e25e81374 (patch)
tree407564eaa6466e8d4cf2eeee0c56dc623243586f /js/helper-classes/3D/view-utils.js
parentd25359c75089215ee48838db081fd3d51cbbd85f (diff)
parent21d74af1e9fc57cc25cea8aa7408beabf79ff2f3 (diff)
downloadninja-9f240b8b9b1f5fb0f145c343ca5e533e25e81374.tar.gz
Merge branch 'master' of github.com:Motorola-Mobility/ninja
Diffstat (limited to 'js/helper-classes/3D/view-utils.js')
-rwxr-xr-xjs/helper-classes/3D/view-utils.js99
1 files changed, 76 insertions, 23 deletions
diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js
index 25e40bac..3b9c44b2 100755
--- a/js/helper-classes/3D/view-utils.js
+++ b/js/helper-classes/3D/view-utils.js
@@ -239,6 +239,27 @@ exports.ViewUtils = Montage.create(Component, {
239 } 239 }
240 }, 240 },
241 241
242 getOffsetParent: {
243 value: function( elt ) {
244 var parent = elt.elementModel.getProperty("offsetParent");
245 if(parent === "none") {
246 return null;
247 }
248 else if(parent) {
249 return parent;
250 } else {
251 parent = elt.offsetParent;
252 if(parent) {
253 elt.elementModel.setProperty("offsetParent", parent);
254 return parent;
255 } else {
256 elt.elementModel.setProperty("offsetParent", "none");
257 return null;
258 }
259 }
260 }
261 },
262
242 getEyePoint: { 263 getEyePoint: {
243 value:function() { 264 value:function() {
244 // this function should use the center of projection - it is currently hard wired to (0,0). 265 // this function should use the center of projection - it is currently hard wired to (0,0).
@@ -360,7 +381,7 @@ exports.ViewUtils = Montage.create(Component, {
360 381
361 // transform the point up the tree 382 // transform the point up the tree
362 var child = elt; 383 var child = elt;
363 var parent = elt.offsetParent; 384 var parent = this.getOffsetParent(elt);
364 while ( parent ) 385 while ( parent )
365 { 386 {
366 // go to screen space of the current child 387 // go to screen space of the current child
@@ -388,7 +409,7 @@ exports.ViewUtils = Montage.create(Component, {
388 } 409 }
389 410
390 child = parent; 411 child = parent;
391 parent = parent.offsetParent; 412 parent = this.getOffsetParent(parent);
392 } 413 }
393 414
394 return pt; 415 return pt;
@@ -413,7 +434,7 @@ exports.ViewUtils = Montage.create(Component, {
413 434
414 if (child === this._stageElement) break; 435 if (child === this._stageElement) break;
415 if (child === this._rootElement) break; 436 if (child === this._rootElement) break;
416 child = child.offsetParent; 437 child = this.getOffsetParent(child);
417 if (child === this._rootElement) break; 438 if (child === this._rootElement) break;
418 } 439 }
419 440
@@ -449,7 +470,7 @@ exports.ViewUtils = Montage.create(Component, {
449 if (pt.length == 2) pt[2] = 0; 470 if (pt.length == 2) pt[2] = 0;
450 471
451 // transform the bounds up the tree 472 // transform the bounds up the tree
452 var parent = child.offsetParent; 473 var parent = this.getOffsetParent(child);
453 // TODO - Should have a different way to check for new template mode 474 // TODO - Should have a different way to check for new template mode
454 if ( parent || (child === this.application.ninja.currentDocument.model.documentRoot) ) 475 if ( parent || (child === this.application.ninja.currentDocument.model.documentRoot) )
455 { 476 {
@@ -498,7 +519,7 @@ exports.ViewUtils = Montage.create(Component, {
498 pt[3] = 1; 519 pt[3] = 1;
499 520
500 // transform the bounds up the tree 521 // transform the bounds up the tree
501 var parent = child.offsetParent; 522 var parent = this.getOffsetParent(child);
502 if ( parent ) 523 if ( parent )
503 { 524 {
504 this.setViewportObj( child ); 525 this.setViewportObj( child );
@@ -701,11 +722,25 @@ exports.ViewUtils = Montage.create(Component, {
701 // optional argument localSpace, if true, puts the top left at (0,0). 722 // optional argument localSpace, if true, puts the top left at (0,0).
702 if (arguments.length < 2) localSpace = false; 723 if (arguments.length < 2) localSpace = false;
703 724
704 var bounds; 725 var bounds, left, top, w, h;
705 var left = elt.offsetLeft, 726 if(elt.elementModel.getProperty("offsetCache")) {
706 top = elt.offsetTop, 727 left = elt.elementModel.getProperty("offsetLeft");
707 w = elt.offsetWidth, 728 top = elt.elementModel.getProperty("offsetTop");
729 w = elt.elementModel.getProperty("offsetWidth");
730 h = elt.elementModel.getProperty("offsetHeight");
731 } else {
732 left = elt.offsetLeft;
733 top = elt.offsetTop;
734 w = elt.offsetWidth;
708 h = elt.offsetHeight; 735 h = elt.offsetHeight;
736 elt.elementModel.setProperty("offsetLeft", left);
737 elt.elementModel.setProperty("offsetTop", top);
738 elt.elementModel.setProperty("offsetWidth", w);
739 elt.elementModel.setProperty("offsetHeight", h);
740 elt.elementModel.setProperty("offsetCache", true);
741 }
742
743
709 744
710// if (elt instanceof SVGSVGElement) { 745// if (elt instanceof SVGSVGElement) {
711 if(elt.nodeName.toLowerCase() === "svg") { 746 if(elt.nodeName.toLowerCase() === "svg") {
@@ -745,21 +780,39 @@ exports.ViewUtils = Montage.create(Component, {
745 780
746 getElementOffset: { 781 getElementOffset: {
747 value: function( elt ) { 782 value: function( elt ) {
748 var xOff = elt.offsetLeft, yOff = elt.offsetTop; 783 var xOff, yOff, offset, parent, border, pS, bl, bt;
749 // if (elt.__ninjaXOff) xOff = elt.__ninjaXOff;
750 // if (elt.__ninjaYOff) yOff = elt.__ninjaYOff;
751 var offset = [xOff, yOff];
752 if(elt.offsetParent && (elt.offsetParent !== this._stageElement))
753 {
754 var pS = elt.ownerDocument.defaultView.getComputedStyle(elt.offsetParent);
755
756 var border = parseInt(pS.getPropertyValue("border"));
757 784
758 if(border) 785 if(elt.elementModel.getProperty("offsetCache")) {
759 { 786 xOff = elt.elementModel.getProperty("offsetLeft");
760 var bl = parseInt(pS.getPropertyValue("border-left-width")), 787 yOff = elt.elementModel.getProperty("offsetTop");
788 } else {
789 xOff = elt.offsetLeft;
790 yOff = elt.offsetTop;
791 elt.elementModel.setProperty("offsetLeft", xOff);
792 elt.elementModel.setProperty("offsetTop", yOff);
793 elt.elementModel.setProperty("offsetCache", true);
794 }
795 offset = [xOff, yOff];
796 parent = this.getOffsetParent(elt);
797 if(parent && (parent !== this._stageElement))
798 {
799 if(parent.elementModel.getProperty("border")) {
800 border = parent.elementModel.getProperty("border");
801 bl = parent.elementModel.getProperty("border-left-width");
802 bt = parent.elementModel.getProperty("border-top-width");
803 } else {
804 if(elt.ownerDocument.defaultView) {
805 pS = elt.ownerDocument.defaultView.getComputedStyle(parent, null);
806 border = parseInt(pS.getPropertyValue("border"));
807 bl = parseInt(pS.getPropertyValue("border-left-width"));
761 bt = parseInt(pS.getPropertyValue("border-top-width")); 808 bt = parseInt(pS.getPropertyValue("border-top-width"));
809 parent.elementModel.setProperty("border", border);
810 parent.elementModel.setProperty("border-left-width", bl);
811 parent.elementModel.setProperty("border-top-width", bt);
812 }
813 }
762 814
815 if(border) {
763 offset[0] += bl; 816 offset[0] += bl;
764 offset[1] += bt; 817 offset[1] += bt;
765 } 818 }
@@ -1072,7 +1125,7 @@ exports.ViewUtils = Montage.create(Component, {
1072 1125
1073 if (elt === this._stageElement) break; 1126 if (elt === this._stageElement) break;
1074 if (elt === this._rootElement) break; 1127 if (elt === this._rootElement) break;
1075 elt = elt.offsetParent; 1128 elt = this.getOffsetParent(elt);
1076 if (elt === this._rootElement) break; 1129 if (elt === this._rootElement) break;
1077 } 1130 }
1078 1131
@@ -1125,7 +1178,7 @@ exports.ViewUtils = Montage.create(Component, {
1125 //mat = offMat.multiply( mat ); 1178 //mat = offMat.multiply( mat );
1126 glmat4.multiply( offMat, mat, mat ); 1179 glmat4.multiply( offMat, mat, mat );
1127 1180
1128 elt = elt.offsetParent; 1181 elt = this.getOffsetParent(elt);
1129 } 1182 }
1130 1183
1131 return mat; 1184 return mat;