Page MenuHomePhabricator

VisualEditor: Clean up phantom mouse event code in ve.ce.ProtectedNode
Closed, ResolvedPublic

Description

Currently, the mouse event handling in phantoms is:

// mouseenter on the protectednode
ve.ce.ProtectedNode.prototype.onProtectedMouseEnter = function () {
	if ( !this.root.getSurface().dragging ) {
		this.createPhantoms();
	}
};

// mousemove on the surface, bound by createPhantoms and unbound by clearPhantoms
ve.ce.ProtectedNode.prototype.onSurfaceMouseMove = function ( e ) {
	var $target = $( e.target );
	if (
		!$target.hasClass( 've-ce-protectedNode-phantom' ) &&
		$target.closest( '.ve-ce-protectedNode' ).length === 0
	) {
		this.clearPhantoms();
	}
};

// mouseout on the surface, bound by createPhantoms and unbound by clearPhantoms
ve.ce.ProtectedNode.prototype.onSurfaceMouseOut = function ( e ) {
	if ( e.toElement === null ) {
		this.clearPhantoms();
	}
};

Issues:

  • the mousemove handler seems to permit moving the mouse directly to a different ProtectedNode without causing the phantoms to be cleared
  • the mouseout handler uses e.toElement, which is a poorly documented property that's allegedly IE-only
  • it's generally very difficult to reason about what this code does or convince oneself that it does something reasonable

Version: unspecified
Severity: normal

Details

Reference
bz55448

Event Timeline

bzimport raised the priority of this task from to High.Nov 22 2014, 2:15 AM
bzimport set Reference to bz55448.

What's even worse is that if somehow another ProtectedNode does manage to show other phantoms, they will replace the first node's phantoms (because of the way ce.Surface manages phantoms), but if for some reason clearPhantoms() isn't called, the first node will continue to track the now-detached phantoms and reposition them when a transaction occurs.

Jdforrester-WMF lowered the priority of this task from High to Low.Jan 9 2015, 10:33 PM

ProtectedNode became FocusableNode, and phantoms became highlights.

the mousemove handler seems to permit moving the mouse directly to a different ProtectedNode without causing the phantoms to be cleared

This seems to be fixed in rGVED138a7f862f24: Fix focusable mouseout.

the mouseout handler uses e.toElement, which is a poorly documented property that's allegedly IE-only

Big rewrite in rGVEDe1b0e33df779: [BREAKING CHANGE] Merge ProtectedNode into FocusableNode changed that to use e.relatedTarget, which is legit, and basically the same (according to http://help.dottoro.com/ljltrsom.php).

it's generally very difficult to reason about what this code does or convince oneself that it does something reasonable

This is still true, but I'm not sure if it's fixable :)

What's even worse is that if somehow another ProtectedNode does manage to show other phantoms, they will replace the first node's phantoms (because of the way ce.Surface manages phantoms), but if for some reason clearPhantoms() isn't called, the first node will continue to track the now-detached phantoms and reposition them when a transaction occurs.

This might still be a problem.

Esanders claimed this task.