diff --git a/devtools/client/inspector/markup/markup.js b/devtools/client/inspector/markup/markup.js index 0837d777246a..bbad275097db 100644 --- a/devtools/client/inspector/markup/markup.js +++ b/devtools/client/inspector/markup/markup.js @@ -130,7 +130,7 @@ function MarkupView(inspector, frame, controllerWindow) { this._elt.addEventListener("click", this._onMouseClick, false); this._elt.addEventListener("mousemove", this._onMouseMove, false); this._elt.addEventListener("mouseleave", this._onMouseLeave, false); - this.doc.body.addEventListener("mouseup", this._onMouseUp); + this.win.addEventListener("mouseup", this._onMouseUp); this.win.addEventListener("keydown", this._onKeyDown, false); this.win.addEventListener("copy", this._onCopy); this._frame.addEventListener("focus", this._onFocus, false); @@ -1621,7 +1621,7 @@ MarkupView.prototype = { this._elt.removeEventListener("click", this._onMouseClick, false); this._elt.removeEventListener("mousemove", this._onMouseMove, false); this._elt.removeEventListener("mouseleave", this._onMouseLeave, false); - this.doc.body.removeEventListener("mouseup", this._onMouseUp); + this.win.removeEventListener("mouseup", this._onMouseUp); this.win.removeEventListener("keydown", this._onKeyDown, false); this.win.removeEventListener("copy", this._onCopy); this._frame.removeEventListener("focus", this._onFocus, false); @@ -1793,8 +1793,8 @@ MarkupContainer.prototype = { // Binding event listeners this.elt.addEventListener("mousedown", this._onMouseDown, false); - this.markup.doc.body.addEventListener("mouseup", this._onMouseUp, true); - this.markup.doc.body.addEventListener("mousemove", this._onMouseMove, true); + this.win.addEventListener("mouseup", this._onMouseUp, true); + this.win.addEventListener("mousemove", this._onMouseMove, true); this.elt.addEventListener("dblclick", this._onToggle, false); if (this.expander) { this.expander.addEventListener("click", this._onToggle, false); @@ -2057,11 +2057,20 @@ MarkupContainer.prototype = { } if (this.isDragging) { - let diff = event.pageY - this._dragStartY; + let x = 0; + let y = event.pageY - this.win.scrollY; + + // Ensure we keep the dragged element within the markup view. + if (y < 0) { + y = 0; + } else if (y >= this.markup.doc.body.offsetHeight - this.win.scrollY) { + y = this.markup.doc.body.offsetHeight - this.win.scrollY - 1; + } + + let diff = y - this._dragStartY + this.win.scrollY; this.elt.style.top = diff + "px"; - let el = this.markup.doc.elementFromPoint(event.pageX - this.win.scrollX, - event.pageY - this.win.scrollY); + let el = this.markup.doc.elementFromPoint(x, y); this.markup.indicateDropTarget(el); } }, @@ -2190,9 +2199,10 @@ MarkupContainer.prototype = { // Remove event listeners this.elt.removeEventListener("mousedown", this._onMouseDown, false); this.elt.removeEventListener("dblclick", this._onToggle, false); - this.markup.doc.body.removeEventListener("mouseup", this._onMouseUp, true); - this.markup.doc.body.removeEventListener("mousemove", - this._onMouseMove, true); + if (this.win) { + this.win.removeEventListener("mouseup", this._onMouseUp, true); + this.win.removeEventListener("mousemove", this._onMouseMove, true); + } this.win = null;