diff options
Diffstat (limited to 'client/src')
4 files changed, 85 insertions, 9 deletions
diff --git a/client/src/com/vaadin/client/WidgetUtil.java b/client/src/com/vaadin/client/WidgetUtil.java index 96f161c4a8..eb6697dda0 100644 --- a/client/src/com/vaadin/client/WidgetUtil.java +++ b/client/src/com/vaadin/client/WidgetUtil.java @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.Map; import java.util.logging.Logger; +import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.AnchorElement; @@ -1243,6 +1244,46 @@ public class WidgetUtil { return Math.abs(num1 - num2) <= PIXEL_EPSILON; } + public static native TextRectangle getBoundingClientRect(Element e) + /*-{ + return e.getBoundingClientRect(); + }-*/; + + public static final class TextRectangle extends JavaScriptObject { + protected TextRectangle() { + } + + public native double getBottom() + /*-{ + return this.bottom; + }-*/; + + public native double getHeight() + /*-{ + return this.height; + }-*/; + + public native double getLeft() + /*-{ + return this.left; + }-*/; + + public native double getRight() + /*-{ + return this.right; + }-*/; + + public native double getTop() + /*-{ + return this.top; + }-*/; + + public native double getWidth() + /*-{ + return this.width; + }-*/; + } + /** * Wrap a css size value and its unit and translate back and forth to the * string representation.<br/> diff --git a/client/src/com/vaadin/client/widget/escalator/RowContainer.java b/client/src/com/vaadin/client/widget/escalator/RowContainer.java index 2fe2070b0d..397336450e 100644 --- a/client/src/com/vaadin/client/widget/escalator/RowContainer.java +++ b/client/src/com/vaadin/client/widget/escalator/RowContainer.java @@ -18,7 +18,7 @@ package com.vaadin.client.widget.escalator; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.TableRowElement; -import com.vaadin.client.widgets.Escalator; +import com.google.gwt.dom.client.TableSectionElement; /** * A representation of the rows in each of the sections (header, body and @@ -192,5 +192,5 @@ public interface RowContainer { * * @return RowContainer root element */ - public Element getElement(); + public TableSectionElement getElement(); } diff --git a/client/src/com/vaadin/client/widgets/Escalator.java b/client/src/com/vaadin/client/widgets/Escalator.java index 4f853a928f..6a8fb311b1 100644 --- a/client/src/com/vaadin/client/widgets/Escalator.java +++ b/client/src/com/vaadin/client/widgets/Escalator.java @@ -1245,7 +1245,7 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker } @Override - public Element getElement() { + public TableSectionElement getElement() { return root; } diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index d6dfdee3b3..c8354dc5ce 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -39,6 +39,7 @@ import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.dom.client.TableCellElement; import com.google.gwt.dom.client.TableRowElement; +import com.google.gwt.dom.client.TableSectionElement; import com.google.gwt.dom.client.Touch; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; @@ -941,6 +942,9 @@ public class Grid<T> extends ResizeComposite implements */ protected static class Editor<T> { + private static final double BUTTON_HEIGHT = 25; + private static final double BUTTON_WIDTH = 50; + private static final double BUTTON_MARGIN = 5; public static final int KEYCODE_SHOW = KeyCodes.KEY_ENTER; public static final int KEYCODE_HIDE = KeyCodes.KEY_ESCAPE; @@ -1256,8 +1260,9 @@ public class Grid<T> extends ResizeComposite implements .getRequiredWidthBoundingClientRectDouble(tr); double height = WidgetUtil .getRequiredHeightBoundingClientRectDouble(tr); - setBounds(editorOverlay, tr.getOffsetLeft(), rowTop + bodyTop - - wrapperTop, width, height); + double overlayTop = rowTop + bodyTop - wrapperTop; + setBounds(editorOverlay, tr.getOffsetLeft(), overlayTop, width, + height); updateHorizontalScrollPosition(); @@ -1297,8 +1302,6 @@ public class Grid<T> extends ResizeComposite implements save(); } }); - setBounds(saveButton.getElement(), 0, tr.getOffsetHeight() + 5, 50, - 25); attachWidget(saveButton, editorOverlay); cancelButton = new Button(); @@ -1311,9 +1314,41 @@ public class Grid<T> extends ResizeComposite implements cancel(); } }); - setBounds(cancelButton.getElement(), 55, tr.getOffsetHeight() + 5, - 50, 25); attachWidget(cancelButton, editorOverlay); + + /* + * We can't use BUTTON_HEIGHT here, becuase it's ignored by at least + * Chrome and Firefox. So we measure it. + */ + double buttonTop = getButtonTop(tr, saveButton.getOffsetHeight()); + setBounds(saveButton.getElement(), 0, buttonTop, BUTTON_WIDTH, + BUTTON_HEIGHT); + setBounds(cancelButton.getElement(), BUTTON_WIDTH + BUTTON_MARGIN, + buttonTop, BUTTON_WIDTH, BUTTON_HEIGHT); + } + + private double getButtonTop(TableRowElement tr, int buttonHeight) { + boolean buttonsShouldBeRenderedBelow = buttonsShouldBeRenderedBelow( + tr, buttonHeight); + final double buttonTop; + if (buttonsShouldBeRenderedBelow) { + buttonTop = tr.getOffsetHeight() + BUTTON_MARGIN; + } else { + buttonTop = -(buttonHeight + BUTTON_MARGIN); + } + return buttonTop; + } + + private boolean buttonsShouldBeRenderedBelow(TableRowElement tr, + int buttonHeight) { + TableSectionElement tfoot = grid.escalator.getFooter().getElement(); + double tfootPageTop = WidgetUtil.getBoundingClientRect(tfoot) + .getTop(); + double trPageBottom = WidgetUtil.getBoundingClientRect(tr) + .getBottom(); + double bottomOfButtons = trPageBottom + buttonHeight + + BUTTON_MARGIN; + return bottomOfButtons < tfootPageTop; } protected void hideOverlay() { |