@@ -173,6 +173,7 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{
173173 this . _context = this . _canvas . getContext ( '2d' ) ;
174174 this . _matrix = new Matrix ( ) ;
175175 this . _zoom = 1 ;
176+ this . _eventCounters = { } ;
176177 // Make sure the first view is focused for keyboard input straight away
177178 if ( ! View . _focused )
178179 View . _focused = this ;
@@ -553,19 +554,49 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{
553554 load : updateFocus
554555 } ) ;
555556
557+ var hitOptions = {
558+ fill : true ,
559+ stroke : true ,
560+ tolerance : 0
561+ } ;
562+
563+ function callEvent ( item , event , bubble ) {
564+ var called = false ;
565+ while ( item ) {
566+ called = item . fire ( event . type , event ) || called ;
567+ if ( called && ( ! bubble || event . _stopped ) )
568+ break ;
569+ item = item . getParent ( ) ;
570+ }
571+ return called ;
572+ }
573+
556574 return {
557575 _createHandlers : function ( ) {
558576 var view = this ;
559577
560578 function mousedown ( event ) {
561579 // Tell the Key class which view should receive keyboard input.
562580 View . _focused = view ;
563- if ( ! ( tool = view . _scope . tool ) )
564- return ;
565581 curPoint = viewToProject ( view , event ) ;
566- if ( tool . onHandleEvent ( 'mousedown' , curPoint , event ) )
567- view . draw ( true ) ;
568582 dragging = true ;
583+
584+ var update = false ;
585+ // TODO: Move this to CanvasView soon!
586+ if ( view . _eventCounters . mousedown ) {
587+ var hit = view . _project . hitTest ( curPoint , hitOptions ) ;
588+ if ( hit && hit . item ) {
589+ update = callEvent ( hit . item , new MouseEvent ( 'mousedown' ,
590+ curPoint , hit . item , event ) , false ) ;
591+ }
592+ }
593+
594+ if ( tool = view . _scope . tool )
595+ update = tool . onHandleEvent ( 'mousedown' , curPoint , event )
596+ || update ;
597+
598+ if ( update )
599+ view . draw ( true ) ;
569600 }
570601
571602 return {
0 commit comments