summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-01 21:47:07 +0000
committerarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-01 21:47:07 +0000
commit86ef30236f2db1a6a55045fb3d8adb903f0d6026 (patch)
tree96e907656453c4981ee991ee312bad66fef9b09b /chrome/test
parent78b048e2ba0abe8b8c3ba00f03f6ff54cb76dcaf (diff)
downloadchromium_src-86ef30236f2db1a6a55045fb3d8adb903f0d6026.zip
chromium_src-86ef30236f2db1a6a55045fb3d8adb903f0d6026.tar.gz
chromium_src-86ef30236f2db1a6a55045fb3d8adb903f0d6026.tar.bz2
Bookmark manager: Make sure we position the context menu inside the window view
BUG=None TEST=In the new bookmark manager. Right click near the lower right corner. The context menu should be shown above and to the left of the mouse. Review URL: http://codereview.chromium.org/554139 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37745 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/data/extensions/bookmarkmanager/js/cr/ui/contextmenuhandler.js34
1 files changed, 33 insertions, 1 deletions
diff --git a/chrome/test/data/extensions/bookmarkmanager/js/cr/ui/contextmenuhandler.js b/chrome/test/data/extensions/bookmarkmanager/js/cr/ui/contextmenuhandler.js
index 0b8442f..5ac0789 100644
--- a/chrome/test/data/extensions/bookmarkmanager/js/cr/ui/contextmenuhandler.js
+++ b/chrome/test/data/extensions/bookmarkmanager/js/cr/ui/contextmenuhandler.js
@@ -68,8 +68,11 @@ cr.define('cr.ui', function() {
* @private
*/
positionMenu_: function(e, menu) {
- // TODO(arv): Do scrolling and overflow.
+ // TODO(arv): Handle scrolled documents when needed.
+
var x, y;
+ // When the user presses the context menu key (on the keyboard) we need
+ // to detect this.
if (e.screenX == 0 && e.screenY == 0) {
var rect = e.currentTarget.getBoundingClientRect();
x = rect.left;
@@ -79,6 +82,35 @@ cr.define('cr.ui', function() {
y = e.clientY;
}
+ var menuRect = menu.getBoundingClientRect();
+ var bodyRect = menu.ownerDocument.body.getBoundingClientRect();
+
+ // Does menu fit below?
+ if (y + menuRect.height > bodyRect.height) {
+ // Does menu fit above?
+ if (y - menuRect.height >= 0) {
+ y -= menuRect.height;
+ } else {
+ // Menu did not fit above nor below.
+ y = 0;
+ // We could resize the menu here but lets not worry about that at this
+ // point.
+ }
+ }
+
+ // Does menu fit to the right?
+ if (x + menuRect.width > bodyRect.width) {
+ // Does menu fit to the left?
+ if (x - menuRect.width >= 0) {
+ x -= menuRect.width;
+ } else {
+ // Menu did not fit to the right nor to the left.
+ x = 0;
+ // We could resize the menu here but lets not worry about that at this
+ // point.
+ }
+ }
+
menu.style.left = x + 'px';
menu.style.top = y + 'px';
},