Improve handling of temporary view focus switch in mousemove.

Closes #841
This commit is contained in:
Jürg Lehni 2016-01-14 11:43:17 +01:00
parent edcb2a3868
commit cee3959bfa
2 changed files with 25 additions and 5 deletions

View file

@ -84,14 +84,14 @@ var DomElement = new function() {
}, },
/** /**
* Checks if element is invisibile (display: none, ...) * Checks if element is invisibile (display: none, ...).
*/ */
isInvisible: function(el) { isInvisible: function(el) {
return DomElement.getSize(el).equals(new Size(0, 0)); return DomElement.getSize(el).equals(new Size(0, 0));
}, },
/** /**
* Checks if element is visibile in current viewport * Checks if element is visibile in current viewport.
*/ */
isInView: function(el) { isInView: function(el) {
// See if the viewport bounds intersect with the windows rectangle // See if the viewport bounds intersect with the windows rectangle
@ -101,6 +101,13 @@ var DomElement = new function() {
DomElement.getBounds(el, true)); DomElement.getBounds(el, true));
}, },
/**
* Checks if element is inside the DOM.
*/
isInserted: function(el) {
return document.body.contains(el);
},
/** /**
* Gets the given property from the element, trying out all browser * Gets the given property from the element, trying out all browser
* prefix variants. * prefix variants.

View file

@ -407,12 +407,21 @@ var View = Base.extend(Emitter, /** @lends View# */{
* Checks whether the view is currently visible within the current browser * Checks whether the view is currently visible within the current browser
* viewport. * viewport.
* *
* @return {Boolean} whether the view is visible * @return {Boolean} {@true if the view is visible}
*/ */
isVisible: function() { isVisible: function() {
return DomElement.isInView(this._element); return DomElement.isInView(this._element);
}, },
/**
* Checks whether the view is inserted into the browser DOM.
*
* @return {Boolean} {@true if the view is inserted}
*/
isInserted: function() {
return DomElement.isInserted(this._element);
},
/** /**
* Scrolls the view by the given vector. * Scrolls the view by the given vector.
* *
@ -799,12 +808,16 @@ new function() { // Injection scope for mouse events on the browser
// Key events are handled too during the mouse over. // Key events are handled too during the mouse over.
// As we switch view, fire one last mousemove in the old // As we switch view, fire one last mousemove in the old
// view, to let items receive receive a mouseleave, etc. // view, to let items receive receive a mouseleave, etc.
handleMouseMove(view, event); if (view)
handleMouseMove(view, event);
prevFocus = view; prevFocus = view;
view = View._focused = tempFocus = target; view = View._focused = tempFocus = target;
} }
} else if (tempFocus && tempFocus === view) { } else if (tempFocus && tempFocus === view) {
// Clear temporary focus again and update it. // Clear temporary focus again and switch back to previous focus
// but only if it is still valid (still in the DOM).
if (prevFocus && !prevFocus.isInserted())
prevFocus = null;
view = View._focused = prevFocus; view = View._focused = prevFocus;
updateFocus(); updateFocus();
} }