diff options
author | Ananya Sen | 2012-05-01 13:39:30 -0700 |
---|---|---|
committer | Ananya Sen | 2012-05-01 13:39:30 -0700 |
commit | c360d1a5cfe894591ae65f892ead11d0ca537b18 (patch) | |
tree | 13964f810d3516dbc02e27ab5bb576fe62366f26 /js/stage/stage.reel/stage.js | |
parent | 3137d919e6b4ccbb2fb68c5920f4376acde3f1f5 (diff) | |
parent | e3fa4c7db57b63c5ac604c9420062de5d0fe413a (diff) | |
download | ninja-c360d1a5cfe894591ae65f892ead11d0ca537b18.tar.gz |
Merge branch 'refs/heads/ninja-internal-master' into Codeview-improvements
Diffstat (limited to 'js/stage/stage.reel/stage.js')
-rwxr-xr-x | js/stage/stage.reel/stage.js | 154 |
1 files changed, 81 insertions, 73 deletions
diff --git a/js/stage/stage.reel/stage.js b/js/stage/stage.reel/stage.js index 8382135d..515165bf 100755 --- a/js/stage/stage.reel/stage.js +++ b/js/stage/stage.reel/stage.js | |||
@@ -224,14 +224,6 @@ exports.Stage = Montage.create(Component, { | |||
224 | // Event details will contain the active document prior to opening a new one | 224 | // Event details will contain the active document prior to opening a new one |
225 | handleOpenDocument: { | 225 | handleOpenDocument: { |
226 | value: function(evt) { | 226 | value: function(evt) { |
227 | |||
228 | var prevActiveDocument = evt.detail; | ||
229 | // Hide current document is one is open | ||
230 | if(prevActiveDocument) { | ||
231 | prevActiveDocument.container.style["display"] = "none"; | ||
232 | if(prevActiveDocument.documentType === "htm" || prevActiveDocument.documentType === "html") this.hideCanvas(true); | ||
233 | } | ||
234 | |||
235 | this.hideCanvas(false); | 227 | this.hideCanvas(false); |
236 | 228 | ||
237 | // Recalculate the canvas sizes because of splitter resizing | 229 | // Recalculate the canvas sizes because of splitter resizing |
@@ -239,29 +231,43 @@ exports.Stage = Montage.create(Component, { | |||
239 | this._canvas.height = this._layoutCanvas.height = this._drawingCanvas.height = this.element.offsetHeight - 11; | 231 | this._canvas.height = this._layoutCanvas.height = this._drawingCanvas.height = this.element.offsetHeight - 11; |
240 | 232 | ||
241 | this._documentRoot = this.application.ninja.currentDocument.documentRoot; | 233 | this._documentRoot = this.application.ninja.currentDocument.documentRoot; |
242 | this._viewport = this.application.ninja.currentDocument.documentRoot.parentNode; | ||
243 | 234 | ||
244 | this.documentOffsetLeft = this._viewport.offsetLeft; | 235 | // Hardcode this value so that it does not fail for the new stage architecture |
245 | this.documentOffsetTop = this._viewport.offsetTop; | 236 | // TODO: Remove marker for old template: NINJA-STAGE-REWORK |
237 | if(this.application.ninja.currentDocument.documentRoot.id === "UserContent") { | ||
238 | this._viewport = this.application.ninja.currentDocument.documentRoot.parentNode; | ||
246 | 239 | ||
247 | // Center the stage | 240 | this.documentOffsetLeft = this._viewport.offsetLeft; |
248 | this.centerStage(); | 241 | this.documentOffsetTop = this._viewport.offsetTop; |
249 | 242 | ||
250 | this._scrollLeft = this._iframeContainer.scrollLeft; | 243 | // Center the stage |
251 | this._scrollTop = this._iframeContainer.scrollTop; | 244 | this.centerStage(); |
252 | this.application.ninja.currentDocument.savedLeftScroll = this._iframeContainer.scrollLeft; | ||
253 | this.application.ninja.currentDocument.savedTopScroll = this._iframeContainer.scrollTop; | ||
254 | 245 | ||
255 | // Hardcode this value so that it does not fail for the new stage architecture | 246 | this._scrollLeft = this._iframeContainer.scrollLeft; |
256 | // TODO: Remove marker for old template: NINJA-STAGE-REWORK | 247 | this._scrollTop = this._iframeContainer.scrollTop; |
257 | this.userContentBorder = 1; //parseInt(this._documentRoot.elementModel.controller.getProperty(this._documentRoot, "border")); | 248 | this.application.ninja.currentDocument.savedLeftScroll = this._iframeContainer.scrollLeft; |
249 | this.application.ninja.currentDocument.savedTopScroll = this._iframeContainer.scrollTop; | ||
258 | 250 | ||
259 | this._userContentLeft = this._documentOffsetLeft - this._scrollLeft + this._userContentBorder; | 251 | this.userContentBorder = parseInt(this._documentRoot.elementModel.controller.getProperty(this._documentRoot, "border")); |
260 | this._userContentTop = this._documentOffsetTop - this._scrollTop + this._userContentBorder; | 252 | |
253 | this._userContentLeft = this._documentOffsetLeft - this._scrollLeft + this._userContentBorder; | ||
254 | this._userContentTop = this._documentOffsetTop - this._scrollTop + this._userContentBorder; | ||
255 | |||
256 | this._iframeContainer.addEventListener("scroll", this, false); | ||
257 | |||
258 | this.application.ninja.currentDocument.iframe.style.opacity = 1.0; | ||
259 | } else { | ||
260 | this.userContentBorder = 0; | ||
261 | |||
262 | this._scrollLeft = 0; | ||
263 | this._scrollTop = 0; | ||
264 | this._userContentLeft = 0; | ||
265 | this._userContentTop = 0; | ||
266 | |||
267 | this.application.ninja.currentDocument._window.addEventListener("scroll", this, false); | ||
268 | } | ||
261 | 269 | ||
262 | this.application.ninja.currentDocument.iframe.style.opacity = 1.0; | ||
263 | 270 | ||
264 | this._iframeContainer.addEventListener("scroll", this, false); | ||
265 | 271 | ||
266 | // TODO - We will need to modify this once we support switching between multiple documents | 272 | // TODO - We will need to modify this once we support switching between multiple documents |
267 | this.application.ninja.toolsData.selectedToolInstance._configure(true); | 273 | this.application.ninja.toolsData.selectedToolInstance._configure(true); |
@@ -419,13 +425,10 @@ exports.Stage = Montage.create(Component, { | |||
419 | handleSelectionChange: { | 425 | handleSelectionChange: { |
420 | value: function(event) { | 426 | value: function(event) { |
421 | // TODO - this is a hack for now because some tools depend on selectionDrawn event for some logic | 427 | // TODO - this is a hack for now because some tools depend on selectionDrawn event for some logic |
422 | if(this.drawNow) | 428 | if(this.drawNow) { |
423 | { | ||
424 | this.draw(); | 429 | this.draw(); |
425 | this.drawNow = false; | 430 | this.drawNow = false; |
426 | } | 431 | } else { |
427 | else | ||
428 | { | ||
429 | this.needsDraw = true; | 432 | this.needsDraw = true; |
430 | } | 433 | } |
431 | } | 434 | } |
@@ -448,11 +451,20 @@ exports.Stage = Montage.create(Component, { | |||
448 | */ | 451 | */ |
449 | handleScroll: { | 452 | handleScroll: { |
450 | value: function() { | 453 | value: function() { |
451 | this._scrollLeft = this._iframeContainer.scrollLeft; | 454 | // TODO: Remove marker for old template: NINJA-STAGE-REWORK |
452 | this._scrollTop = this._iframeContainer.scrollTop; | 455 | if(this.application.ninja.currentDocument.documentRoot.id === "UserContent") { |
456 | this._scrollLeft = this._iframeContainer.scrollLeft; | ||
457 | this._scrollTop = this._iframeContainer.scrollTop; | ||
458 | |||
459 | this.userContentLeft = this._documentOffsetLeft - this._scrollLeft + this._userContentBorder; | ||
460 | this.userContentTop = this._documentOffsetTop - this._scrollTop + this._userContentBorder; | ||
461 | } else { | ||
462 | this._scrollLeft = this.application.ninja.currentDocument.documentRoot.scrollLeft; | ||
463 | this._scrollTop = this.application.ninja.currentDocument.documentRoot.scrollTop; | ||
453 | 464 | ||
454 | this.userContentLeft = this._documentOffsetLeft - this._scrollLeft + this._userContentBorder; | 465 | this.userContentLeft = -this._scrollLeft; |
455 | this.userContentTop = this._documentOffsetTop - this._scrollTop + this._userContentBorder; | 466 | this.userContentTop = -this._scrollTop; |
467 | } | ||
456 | 468 | ||
457 | // Need to clear the snap cache and set up the drag plane | 469 | // Need to clear the snap cache and set up the drag plane |
458 | //snapManager.setupDragPlaneFromPlane( workingPlane ); | 470 | //snapManager.setupDragPlaneFromPlane( workingPlane ); |
@@ -461,7 +473,6 @@ exports.Stage = Montage.create(Component, { | |||
461 | this.needsDraw = true; | 473 | this.needsDraw = true; |
462 | this.layout.draw(); | 474 | this.layout.draw(); |
463 | //this._toolsList.action("DrawHandles"); | 475 | //this._toolsList.action("DrawHandles"); |
464 | |||
465 | } | 476 | } |
466 | }, | 477 | }, |
467 | 478 | ||
@@ -521,62 +532,59 @@ exports.Stage = Montage.create(Component, { | |||
521 | }, | 532 | }, |
522 | 533 | ||
523 | /** | 534 | /** |
524 | * GetSelectableElement: Returns a selectable object (direct child of current container) at clicked point | 535 | * GetElement: Returns the element or selectable element under the X,Y coordinates passed as an obj with x,y |
525 | * | 536 | * |
526 | * @param: X,Y | 537 | * @param position: mouse event |
527 | * @return: Returns the current container if the the X,Y hits an element in the exclusion list | 538 | * @param selectable (default == null) if true this will return the current container element |
539 | * @return: Returns the element or container or null if the the X,Y hits the exclusion list and tool cannot operate on stage | ||
528 | */ | 540 | */ |
529 | GetSelectableElement: { | 541 | getElement: { |
530 | value: function(pos) { | 542 | value: function(position, selectable) { |
531 | var item = this.GetElement(pos); | 543 | var point, element; |
532 | if(this.application.ninja.currentDocument.inExclusion(item) !== -1) { | 544 | |
533 | return this.application.ninja.currentSelectedContainer; | 545 | point = webkitConvertPointFromPageToNode(this.canvas, new WebKitPoint(position.pageX, position.pageY)); |
546 | element = this.application.ninja.currentDocument.GetElementFromPoint(point.x + this.scrollLeft,point.y + this.scrollTop); | ||
547 | |||
548 | // workaround Chrome 3d bug | ||
549 | if(this.application.ninja.toolsData.selectedToolInstance._canSnap && this.application.ninja.currentDocument.inExclusion(element) !== -1) { | ||
550 | element = this.getElementUsingSnapping(point); | ||
534 | } | 551 | } |
535 | var activeContainerId = this.application.ninja.currentSelectedContainer.uuid; | ||
536 | if(item.parentNode.uuid === activeContainerId) { | ||
537 | return item; | ||
538 | } else { | ||
539 | var outerElement = item.parentNode; | ||
540 | 552 | ||
541 | while(outerElement.parentNode && outerElement.parentNode.uuid !== activeContainerId) { | 553 | if(selectable) { |
542 | // If element is higher up than current container then return | 554 | |
543 | if(outerElement.id === "UserContent") return; | 555 | if(this.application.ninja.currentDocument.inExclusion(element) !== -1) { |
544 | // else keep going up the chain | 556 | return this.application.ninja.currentSelectedContainer; |
545 | outerElement = outerElement.parentNode; | ||
546 | } | 557 | } |
547 | 558 | ||
548 | return outerElement; | 559 | var activeContainerId = this.application.ninja.currentSelectedContainer.uuid; |
549 | } | 560 | if(element.parentNode.uuid === activeContainerId) { |
550 | } | 561 | return element; |
551 | }, | 562 | } else { |
563 | var outerElement = element.parentNode; | ||
552 | 564 | ||
553 | /** | 565 | while(outerElement.parentNode && outerElement.parentNode.uuid !== activeContainerId) { |
554 | * GetElement: Returns the object under the X,Y coordinates passed as an obj with x,y | 566 | // If element is higher up than current container then return |
555 | * | 567 | if(outerElement.id === "UserContent") return; |
556 | * @param: X,Y | 568 | // else keep going up the chain |
557 | * @return: Returns the Object or null if the the X,Y hits the exclusion list and tool cannot operate on stage | 569 | outerElement = outerElement.parentNode; |
558 | */ | 570 | } |
559 | GetElement: { | 571 | |
560 | value: function(pos) { | 572 | return outerElement; |
561 | var point = webkitConvertPointFromPageToNode(this.canvas, new WebKitPoint(pos.pageX, pos.pageY)), | 573 | } |
562 | elt = this.application.ninja.currentDocument.GetElementFromPoint(point.x + this.scrollLeft,point.y + this.scrollTop); | ||
563 | 574 | ||
564 | // workaround Chrome 3d bug | ||
565 | if(this.application.ninja.toolsData.selectedToolInstance._canSnap && this.application.ninja.currentDocument.inExclusion(elt) !== -1) { | ||
566 | return this._getElementUsingSnapping(point); | ||
567 | } else { | 575 | } else { |
568 | return elt; | 576 | return element; |
569 | } | 577 | } |
570 | } | 578 | } |
571 |