// ======================================================================== // SproutCore -- JavaScript Application Framework // Copyright ©2006-2008, Sprout Systems, Inc. and contributors. // Portions copyright ©2008 Apple Inc. All rights reserved. // ======================================================================== /** This view draws selection handles for a given designer. It will also forward any mouse events to the underlying designer. */ SC.SelectionHandlesView = SC.View.extend( /** @scope SC.SelectionHandlesView.prototype */ { /** The designer that owns this selection. mouse and keyboard events are forwarded to this. */ designer: null, classNames: 'handles', render: function(context, firstTime) { var designer = this.get('designer'), vertical = designer ? designer.get('canResizeVertical') : NO, horizontal = designer ? designer.get('canResizeHorizontal') : NO, handles ; // render handles if (firstTime || (vertical !== this._vertical) || (horizontal === this._horizontal)) { this._vertical = vertical ; this._horizontal = horizontal; if (vertical && horizontal) { handles = ['top left', 'top right', 'bottom left','bottom right']; } else if (vertical) { handles = 'top bottom'.w(); } else if (horizontal) { handles = 'left right'.w(); } else handles = []; handles.forEach(function(classNames) { context.begin('span') .classNames(classNames.w()) .addClass('handle') .end(); }, this); } }, // .......................................................... // EVENT HANDLING // // By default just forward to designer mouseDown: function(evt) { var d = this.designer; return (d && d.mouseDown) ? d.mouseDown(evt) : null; }, mouseUp: function(evt) { var d = this.designer; return (d && d.mouseUp) ? d.mouseUp(evt) : null; }, mouseMoved: function(evt) { var d = this.designer; return (d && d.mouseMoved) ? d.mouseMoved(evt) : null; }, mouseDragged: function(evt) { var d = this.designer; return (d && d.mouseDragged) ? d.mouseDragged(evt) : null; } });