From cd6cbd2ff792a65ffa3103de2b49adb7d25f1c58 Mon Sep 17 00:00:00 2001 From: sbosse Date: Mon, 21 Jul 2025 23:43:06 +0200 Subject: [PATCH] Mon 21 Jul 22:43:21 CEST 2025 --- js/ui/mxgraph/src/js/util/mxMouseEvent.js | 244 ++++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 js/ui/mxgraph/src/js/util/mxMouseEvent.js diff --git a/js/ui/mxgraph/src/js/util/mxMouseEvent.js b/js/ui/mxgraph/src/js/util/mxMouseEvent.js new file mode 100644 index 0000000..875bac4 --- /dev/null +++ b/js/ui/mxgraph/src/js/util/mxMouseEvent.js @@ -0,0 +1,244 @@ +/** + * Copyright (c) 2006-2015, JGraph Ltd + * Copyright (c) 2006-2015, Gaudenz Alder + */ +/** + * Class: mxMouseEvent + * + * Base class for all mouse events in mxGraph. A listener for this event should + * implement the following methods: + * + * (code) + * graph.addMouseListener( + * { + * mouseDown: function(sender, evt) + * { + * mxLog.debug('mouseDown'); + * }, + * mouseMove: function(sender, evt) + * { + * mxLog.debug('mouseMove'); + * }, + * mouseUp: function(sender, evt) + * { + * mxLog.debug('mouseUp'); + * } + * }); + * (end) + * + * Constructor: mxMouseEvent + * + * Constructs a new event object for the given arguments. + * + * Parameters: + * + * evt - Native mouse event. + * state - Optional under the mouse. + * + */ +function mxMouseEvent(evt, state) +{ + this.evt = evt; + this.state = state; + this.sourceState = state; +}; + +/** + * Variable: consumed + * + * Holds the consumed state of this event. + */ +mxMouseEvent.prototype.consumed = false; + +/** + * Variable: evt + * + * Holds the inner event object. + */ +mxMouseEvent.prototype.evt = null; + +/** + * Variable: graphX + * + * Holds the x-coordinate of the event in the graph. This value is set in + * . + */ +mxMouseEvent.prototype.graphX = null; + +/** + * Variable: graphY + * + * Holds the y-coordinate of the event in the graph. This value is set in + * . + */ +mxMouseEvent.prototype.graphY = null; + +/** + * Variable: state + * + * Holds the optional associated with this event. + */ +mxMouseEvent.prototype.state = null; + +/** + * Variable: sourceState + * + * Holds the that was passed to the constructor. This can be + * different from depending on the result of . + */ +mxMouseEvent.prototype.sourceState = null; + +/** + * Function: getEvent + * + * Returns . + */ +mxMouseEvent.prototype.getEvent = function() +{ + return this.evt; +}; + +/** + * Function: getSource + * + * Returns the target DOM element using for . + */ +mxMouseEvent.prototype.getSource = function() +{ + return mxEvent.getSource(this.evt); +}; + +/** + * Function: isSource + * + * Returns true if the given is the source of . + */ +mxMouseEvent.prototype.isSource = function(shape) +{ + if (shape != null) + { + return mxUtils.isAncestorNode(shape.node, this.getSource()); + } + + return false; +}; + +/** + * Function: getX + * + * Returns . + */ +mxMouseEvent.prototype.getX = function() +{ + return mxEvent.getClientX(this.getEvent()); +}; + +/** + * Function: getY + * + * Returns . + */ +mxMouseEvent.prototype.getY = function() +{ + return mxEvent.getClientY(this.getEvent()); +}; + +/** + * Function: getGraphX + * + * Returns . + */ +mxMouseEvent.prototype.getGraphX = function() +{ + return this.graphX; +}; + +/** + * Function: getGraphY + * + * Returns . + */ +mxMouseEvent.prototype.getGraphY = function() +{ + return this.graphY; +}; + +/** + * Function: getState + * + * Returns . + */ +mxMouseEvent.prototype.getState = function() +{ + return this.state; +}; + +/** + * Function: getCell + * + * Returns the in is not null. + */ +mxMouseEvent.prototype.getCell = function() +{ + var state = this.getState(); + + if (state != null) + { + return state.cell; + } + + return null; +}; + +/** + * Function: isPopupTrigger + * + * Returns true if the event is a popup trigger. + */ +mxMouseEvent.prototype.isPopupTrigger = function() +{ + return mxEvent.isPopupTrigger(this.getEvent()); +}; + +/** + * Function: isConsumed + * + * Returns . + */ +mxMouseEvent.prototype.isConsumed = function() +{ + return this.consumed; +}; + +/** + * Function: consume + * + * Sets to true and invokes preventDefault on the native event + * if such a method is defined. This is used mainly to avoid the cursor from + * being changed to a text cursor in Webkit. You can use the preventDefault + * flag to disable this functionality. + * + * Parameters: + * + * preventDefault - Specifies if the native event should be canceled. Default + * is true. + */ +mxMouseEvent.prototype.consume = function(preventDefault) +{ + preventDefault = (preventDefault != null) ? preventDefault : true; + + if (preventDefault && this.evt.preventDefault) + { + this.evt.preventDefault(); + } + + // Workaround for images being dragged in IE + // Does not change returnValue in Opera + if (mxClient.IS_IE) + { + this.evt.returnValue = true; + } + + // Sets local consumed state + this.consumed = true; +};