Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Unified Diff: chrome/browser/resources/new_new_tab.js

Issue 173090: NNTP: Limit the dragged item to the viewport boundaries.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/new_new_tab.js
===================================================================
--- chrome/browser/resources/new_new_tab.js (revision 23750)
+++ chrome/browser/resources/new_new_tab.js (working copy)
@@ -1477,12 +1477,27 @@
},
handleDrag: function(e) {
+ // Moves the drag item making sure that it is not displayed outside the
+ // browser viewport.
var item = mostVisited.getItem(e.target);
var rect = document.querySelector('#most-visited').getBoundingClientRect();
item.style.pointerEvents = 'none';
- item.style.left = this.startX + e.screenX - this.startScreenX + 'px';
- item.style.top = this.startY + e.screenY - this.startScreenY + 'px';
+ var x = this.startX + e.screenX - this.startScreenX;
+ var y = this.startY + e.screenY - this.startScreenY;
+
+ // The position of the item is relative to #most-visited so we need to
+ // subtract that when calculation the allowed position.
Miranda Callahan 2009/08/19 22:49:02 s/calculation/calculating
+ x = Math.max(x, -rect.left);
+ x = Math.min(x, document.body.clientWidth - rect.left - item.offsetWidth -
+ 2);
+ // The shadow is 2px
+ y = Math.max(-rect.top, y);
+ y = Math.min(y, document.body.clientHeight - rect.top - item.offsetHeight -
+ 2);
+
+ item.style.left = x + 'px';
+ item.style.top = y + 'px';
},
// We listen to mousedown to get the relative position of the cursor for dnd.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698