From cee3959bfa3baf8837ec06604f1e75f69639be18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Thu, 14 Jan 2016 11:43:17 +0100 Subject: [PATCH] Improve handling of temporary view focus switch in mousemove. Closes #841 --- src/dom/DomElement.js | 11 +++++++++-- src/view/View.js | 19 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/dom/DomElement.js b/src/dom/DomElement.js index fa737af9..06ead1ea 100644 --- a/src/dom/DomElement.js +++ b/src/dom/DomElement.js @@ -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) { 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) { // See if the viewport bounds intersect with the windows rectangle @@ -101,6 +101,13 @@ var DomElement = new function() { 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 * prefix variants. diff --git a/src/view/View.js b/src/view/View.js index e4a5d315..570a25c0 100644 --- a/src/view/View.js +++ b/src/view/View.js @@ -407,12 +407,21 @@ var View = Base.extend(Emitter, /** @lends View# */{ * Checks whether the view is currently visible within the current browser * viewport. * - * @return {Boolean} whether the view is visible + * @return {Boolean} {@true if the view is visible} */ isVisible: function() { 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. * @@ -799,12 +808,16 @@ new function() { // Injection scope for mouse events on the browser // Key events are handled too during the mouse over. // As we switch view, fire one last mousemove in the old // view, to let items receive receive a mouseleave, etc. - handleMouseMove(view, event); + if (view) + handleMouseMove(view, event); prevFocus = view; view = View._focused = tempFocus = target; } } 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; updateFocus(); }