]> source.dussan.org Git - vaadin-framework.git/commitdiff
some changes to context menu positioning
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 6 Nov 2007 12:29:21 +0000 (12:29 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 6 Nov 2007 12:29:21 +0000 (12:29 +0000)
svn changeset:2721/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/ContextMenu.java
src/com/itmill/toolkit/terminal/gwt/public/default/common/common.css

index 82bbfadffc4948e273edf258fefc091449ba2e56..f488e9441b25c5273ca51f9c29daa8d0a8575659 100644 (file)
@@ -1,6 +1,5 @@
 package com.itmill.toolkit.terminal.gwt.client.ui;
 
-import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.MenuBar;
 import com.google.gwt.user.client.ui.MenuItem;
@@ -12,6 +11,10 @@ public class ContextMenu extends PopupPanel {
 
        private CMenuBar menu = new CMenuBar();
 
+       private int left;
+
+       private int top;
+
        /**
         * This method should be used only by Client object as only one per client
         * should exists. Request an instance via client.getContextMenu();
@@ -41,6 +44,8 @@ public class ContextMenu extends PopupPanel {
         * @param top
         */
        public void showAt(int left, int top) {
+               this.left = left;
+               this.top = top;
                menu.clearItems();
                Action[] actions = actionOwner.getActions();
                for (int i = 0; i < actions.length; i++) {
@@ -48,15 +53,26 @@ public class ContextMenu extends PopupPanel {
                        menu.addItem(new MenuItem(a.getHTML(), true, a));
                }
 
-               setPopupPosition(left, top);
-               show();
-               // fix position if "outside" screen
-               if (DOM.getElementPropertyInt(getElement(), "offsetWidth") + left > Window
-                               .getClientWidth()) {
-                       left = Window.getClientWidth()
-                                       - DOM.getElementPropertyInt(getElement(), "offsetWidth");
-                       setPopupPosition(left, top);
-               }
+               this.setPopupPositionAndShow(new PositionCallback() {
+                       public void setPosition(int offsetWidth, int offsetHeight) {
+                               // mac FF gets bad width due GWT popups overflow hacks,
+                               // re-determine width
+                               offsetWidth = menu.getOffsetWidth();
+                               int left = ContextMenu.this.left;
+                               int top = ContextMenu.this.top;
+                               if (offsetWidth + left > Window.getClientWidth()) {
+                                       left = left - offsetWidth;
+                                       if (left < 0)
+                                               left = 0;
+                               }
+                               if (offsetHeight + top > Window.getClientHeight()) {
+                                       top = top - offsetHeight;
+                                       if (top < 0)
+                                               top = 0;
+                               }
+                               setPopupPosition(left, top);
+                       }
+               });
        }
 
        public void showAt(ActionOwner ao, int left, int top) {
index 239549ecc8a056df924fdd7d91e6c2acf3852929..274164d0cfb3d759d49f22a66ee521b3497eb119 100644 (file)
@@ -65,6 +65,7 @@
        padding: 2px 20px 2px 5px;
        cursor: pointer;
        vertical-align: middle;
+       white-space: nowrap;
 }
 
 .i-contextmenu .gwt-MenuItem-selected {