1 // ========================================================================
  2 // SproutCore -- JavaScript Application Framework
  3 // Copyright ©2006-2011, Strobe Inc. and contributors.
  4 // Portions copyright ©2008 Apple Inc.  All rights reserved.
  5 // ========================================================================
  6 
  7 /**
  8   This View is used by Greenhouse when application is in design mode
  9   This view draws selection handles for a given designer.  It will also
 10   forward any mouse events to the underlying designer.
 11 */
 12 SC.SelectionHandlesView = SC.View.extend({
 13 
 14   /**
 15     The designer that owns this selection.  mouse and keyboard events are
 16     forwarded to this.
 17   */
 18   designer: null,
 19 
 20   classNames: 'handles',
 21 
 22   render: function(context, firstTime) {
 23     var designer = this.get('designer'),
 24         vertical = designer ? designer.get('canResizeVertical') : NO,
 25         horizontal = designer ? designer.get('canResizeHorizontal') : NO,
 26         handles ;
 27 
 28     // render handles
 29     if (firstTime || (vertical !== this._vertical) || (horizontal === this._horizontal)) {
 30       this._vertical = vertical ;
 31       this._horizontal = horizontal;
 32 
 33       if (vertical && horizontal) {
 34         handles = ['top left', 'top right', 'bottom left','bottom right'];
 35       } else if (vertical) {
 36         handles = ['top', 'bottom'];
 37       } else if (horizontal) {
 38         handles = ['left', 'right'];
 39       } else handles = [];
 40 
 41 
 42       handles.forEach(function(classNames) {
 43         context.begin('span')
 44           .addClass(SC.String.w(classNames))
 45           .addClass('handle')
 46           .end();
 47       }, this);
 48     }
 49 
 50   },
 51 
 52   // ..........................................................
 53   // EVENT HANDLING
 54   //
 55   // By default just forward to designer
 56 
 57   mouseDown: function(evt) {
 58     var d = this.designer;
 59     return (d && d.mouseDown) ? d.mouseDown(evt) : null;
 60   },
 61 
 62   mouseUp: function(evt) {
 63     var d = this.designer;
 64     return (d && d.mouseUp) ? d.mouseUp(evt) : null;
 65   },
 66 
 67   mouseMoved: function(evt) {
 68     var d = this.designer;
 69     return (d && d.mouseMoved) ? d.mouseMoved(evt) : null;
 70   },
 71 
 72   mouseDragged: function(evt) {
 73     var d = this.designer;
 74     return (d && d.mouseDragged) ? d.mouseDragged(evt) : null;
 75   }
 76 
 77 });
 78