mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Streamline View#_countItemEvent() code a bit.
This commit is contained in:
parent
0cfa83fc32
commit
5fa0810ca3
1 changed files with 13 additions and 12 deletions
|
@ -106,8 +106,7 @@ var View = Base.extend(Emitter, /** @lends View# */{
|
||||||
this._frameItemCount = 0;
|
this._frameItemCount = 0;
|
||||||
// Count the installed native and virtual item events,
|
// Count the installed native and virtual item events,
|
||||||
// see #_countItemEvent():
|
// see #_countItemEvent():
|
||||||
this._itemNativeEvents = {};
|
this._itemEvents = { native: {}, virtual: {} };
|
||||||
this._itemVirtualEvents = {};
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1139,7 +1138,7 @@ new function() { // Injection scope for event handling on the browser
|
||||||
* Required by code that is counting the amount of required natives events.
|
* Required by code that is counting the amount of required natives events.
|
||||||
* The mapping is native -> virtual.
|
* The mapping is native -> virtual.
|
||||||
*/
|
*/
|
||||||
var itemNativeEvents = {
|
var itemEventsMap = {
|
||||||
mousedown: {
|
mousedown: {
|
||||||
mousedown: 1,
|
mousedown: 1,
|
||||||
mousedrag: 1,
|
mousedrag: 1,
|
||||||
|
@ -1182,12 +1181,13 @@ new function() { // Injection scope for event handling on the browser
|
||||||
* tools.
|
* tools.
|
||||||
*/
|
*/
|
||||||
_handleMouseEvent: function(type, event, point) {
|
_handleMouseEvent: function(type, event, point) {
|
||||||
var hitItems = this._itemNativeEvents[type],
|
var itemEvents = this._itemEvents,
|
||||||
|
hitItems = itemEvents.native[type],
|
||||||
tool = this._scope.tool,
|
tool = this._scope.tool,
|
||||||
view = this;
|
view = this;
|
||||||
|
|
||||||
function responds(type) {
|
function responds(type) {
|
||||||
return view._itemVirtualEvents[type] || view.responds(type)
|
return itemEvents.virtual[type] || view.responds(type)
|
||||||
|| tool && tool.responds(type);
|
|| tool && tool.responds(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1329,16 +1329,17 @@ new function() { // Injection scope for event handling on the browser
|
||||||
|
|
||||||
_countItemEvent: function(type, sign) {
|
_countItemEvent: function(type, sign) {
|
||||||
// If the view requires counting of installed mouse events,
|
// If the view requires counting of installed mouse events,
|
||||||
// change the event counters now according to itemNativeEvents
|
// change the event counters now according to itemEventsMap
|
||||||
// (defined in the code further above).
|
// (defined in the code further above).
|
||||||
var nativeEvents = this._itemNativeEvents,
|
var itemEvents = this._itemEvents,
|
||||||
virtualEvents = this._itemVirtualEvents;
|
native = itemEvents.native,
|
||||||
for (var key in itemNativeEvents) {
|
virtual = itemEvents.virtual;
|
||||||
nativeEvents[key] = (nativeEvents[key] || 0)
|
for (var key in itemEventsMap) {
|
||||||
+ (itemNativeEvents[key][type] || 0) * sign;
|
native[key] = (native[key] || 0)
|
||||||
|
+ (itemEventsMap[key][type] || 0) * sign;
|
||||||
}
|
}
|
||||||
// Also update the count of virtual events installed.
|
// Also update the count of virtual events installed.
|
||||||
virtualEvents[type] = (virtualEvents[type] || 0) + sign;
|
virtual[type] = (virtual[type] || 0) + sign;
|
||||||
},
|
},
|
||||||
|
|
||||||
statics: {
|
statics: {
|
||||||
|
|
Loading…
Reference in a new issue