From 7f65fde61b2251b4c756df54a2b8e3a0fb3fe7b3 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 10 Nov 2009 09:31:45 +0000 Subject: [PATCH] Merged [9694] "Test case and fix for #3639 - DateField's popup calendar sometimes rendered out of sight" from 6.1 svn changeset:9696/svn branch:6.2 --- .../gwt/client/ui/VPopupCalendar.java | 37 +++-- .../datefield/DateFieldPopupOffScreen.html | 157 ++++++++++++++++++ .../datefield/DateFieldPopupOffScreen.java | 63 +++++++ 3 files changed, 247 insertions(+), 10 deletions(-) create mode 100644 tests/src/com/vaadin/tests/components/datefield/DateFieldPopupOffScreen.html create mode 100644 tests/src/com/vaadin/tests/components/datefield/DateFieldPopupOffScreen.java diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java index 9b74167689..0f269722de 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java @@ -78,19 +78,36 @@ public class VPopupCalendar extends VTextualDate implements Paintable, Field, public void setPosition(int offsetWidth, int offsetHeight) { final int w = offsetWidth; final int h = offsetHeight; + final int browserWindowWidth = Window.getClientWidth() + + Window.getScrollLeft(); + final int browserWindowHeight = Window.getClientHeight() + + Window.getScrollTop(); int t = calendarToggle.getAbsoluteTop(); int l = calendarToggle.getAbsoluteLeft(); - if (l + w > Window.getClientWidth() - + Window.getScrollLeft()) { - l = Window.getClientWidth() + Window.getScrollLeft() - - w; + + // Add a little extra space to the right to avoid + // problems with IE6/IE7 scrollbars and to make it look + // nicer. + int extraSpace = 30; + + boolean overflowRight = false; + if (l + +w + extraSpace > browserWindowWidth) { + overflowRight = true; + // Part of the popup is outside the browser window + // (to the right) + l = browserWindowWidth - w - extraSpace; } - if (t + h + calendarToggle.getOffsetHeight() + 30 > Window - .getClientHeight() - + Window.getScrollTop()) { - t = Window.getClientHeight() + Window.getScrollTop() - - h - calendarToggle.getOffsetHeight() - 30; - l += calendarToggle.getOffsetWidth(); + + if (t + h + calendarToggle.getOffsetHeight() + 30 > browserWindowHeight) { + // Part of the popup is outside the browser window + // (below) + t = browserWindowHeight - h + - calendarToggle.getOffsetHeight() - 30; + if (!overflowRight) { + // Show to the right of the popup button unless we + // are in the lower right corner of the screen + l += calendarToggle.getOffsetWidth(); + } } // fix size diff --git a/tests/src/com/vaadin/tests/components/datefield/DateFieldPopupOffScreen.html b/tests/src/com/vaadin/tests/components/datefield/DateFieldPopupOffScreen.html new file mode 100644 index 0000000000..6bc285ee72 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/datefield/DateFieldPopupOffScreen.html @@ -0,0 +1,157 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.datefield.DateFieldPopupOffScreen
screenCapture
waitForVaadin
mouseClickvaadin=runcomvaadintestscomponentsdatefieldDateFieldPopupOffScreen::/VGridLayout[0]/AbsolutePanel[0]/ChildComponentContainer[2]/VPopupCalendar[0]/domChild[1]10,10
waitForVaadin
pause300
waitForVaadin
screenCapture
mouseClickvaadin=runcomvaadintestscomponentsdatefieldDateFieldPopupOffScreen::/VGridLayout[0]/AbsolutePanel[0]/ChildComponentContainer[3]/VPopupCalendar[0]/domChild[1]10,12
waitForVaadin
pause300
waitForVaadin
screenCapture
mouseClickvaadin=runcomvaadintestscomponentsdatefieldDateFieldPopupOffScreen::/VGridLayout[0]/AbsolutePanel[0]/ChildComponentContainer[4]/VPopupCalendar[0]/domChild[1]8,10
waitForVaadin
pause300
waitForVaadin
screenCapture
mouseClickvaadin=runcomvaadintestscomponentsdatefieldDateFieldPopupOffScreen::/VGridLayout[0]/AbsolutePanel[0]/ChildComponentContainer[1]/VPopupCalendar[0]/domChild[1]7,13
waitForVaadin
pause300
waitForVaadin
screenCapture
mouseClickvaadin=runcomvaadintestscomponentsdatefieldDateFieldPopupOffScreen::/VGridLayout[0]/AbsolutePanel[0]/ChildComponentContainer[0]/VPopupCalendar[0]/domChild[1]11,14
waitForVaadin
pause300
waitForVaadin
screenCapture
+ + diff --git a/tests/src/com/vaadin/tests/components/datefield/DateFieldPopupOffScreen.java b/tests/src/com/vaadin/tests/components/datefield/DateFieldPopupOffScreen.java new file mode 100644 index 0000000000..1690bd61ce --- /dev/null +++ b/tests/src/com/vaadin/tests/components/datefield/DateFieldPopupOffScreen.java @@ -0,0 +1,63 @@ +package com.vaadin.tests.components.datefield; + +import java.sql.Date; + +import com.vaadin.tests.components.AbstractTestCase; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.DateField; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.Window; + +public class DateFieldPopupOffScreen extends AbstractTestCase { + + @Override + protected String getDescription() { + return "Test for the popup position from a DateField. The popup should always be on-screen even if the DateField is close the the edge of the browser."; + } + + @Override + protected Integer getTicketNumber() { + return 3639; + } + + @Override + public void init() { + Window mainWindow = new Window(getClass().getName()); + + GridLayout mainLayout = new GridLayout(3, 3); + mainLayout.setSizeFull(); + + DateField df; + + df = createDateField(); + mainLayout.addComponent(df, 2, 0); + mainLayout.setComponentAlignment(df, Alignment.TOP_RIGHT); + + df = createDateField(); + mainLayout.addComponent(df, 2, 1); + mainLayout.setComponentAlignment(df, Alignment.MIDDLE_RIGHT); + + df = createDateField(); + mainLayout.addComponent(df, 2, 2); + mainLayout.setComponentAlignment(df, Alignment.BOTTOM_RIGHT); + + df = createDateField(); + mainLayout.addComponent(df, 0, 2); + mainLayout.setComponentAlignment(df, Alignment.BOTTOM_LEFT); + + df = createDateField(); + mainLayout.addComponent(df, 1, 2); + mainLayout.setComponentAlignment(df, Alignment.BOTTOM_CENTER); + + mainWindow.setContent(mainLayout); + setMainWindow(mainWindow); + } + + private DateField createDateField() { + DateField df = new DateField(); + df + .setDescription("This is a long, multiline tooltip.
It should always be on screen so it can be read."); + df.setValue(new Date(1000000L)); + return df; + } +} -- 2.39.5