Now allows IE9 to use non-lazy mode aswell (remains to be seen if IE9 also sometimes produces extra resize events)
svn changeset:18471/svn branch:6.6
private boolean immediate;
+ private boolean resizeLazy = false;
+
+ public static final String RESIZE_LAZY = "rL";
/**
* Reference to the parent frame/iframe. Null if there is no parent (i)frame
* or if the application and parent frame are in different domains.
connection = client;
immediate = uidl.hasAttribute("immediate");
-
+ resizeLazy = uidl.hasAttribute(RESIZE_LAZY);
String newTheme = uidl.getStringAttribute("theme");
if (theme != null && !newTheme.equals(theme)) {
// Complete page refresh is needed due css can affect layout
*/
private void onResize() {
/*
- * IE will give us some false resize events due to problems with
- * scrollbars. Firefox 3 might also produce som extra events. We
- * postpone both the re-layouting and the server side event for a while
- * to deal with these issues.
+ * IE (pre IE9 at least) will give us some false resize events due to
+ * problems with scrollbars. Firefox 3 might also produce some extra
+ * events. We postpone both the re-layouting and the server side event
+ * for a while to deal with these issues.
*
- * We also postpone these events to avoid slowness when resizing the
+ * We may also postpone these events to avoid slowness when resizing the
* browser window. Constantly recalculating the layout causes the resize
- * operation to be really slow.
+ * operation to be really slow with complex layouts.
*/
- delayedResizeExecutor.trigger();
+ boolean lazy = resizeLazy
+ || (BrowserInfo.get().isIE() && BrowserInfo.get()
+ .getIEVersion() <= 8) || BrowserInfo.get().isFF3();
+
+ if (lazy) {
+ delayedResizeExecutor.trigger();
+ } else {
+ windowSizeMaybeChanged(Window.getClientWidth(),
+ Window.getClientHeight());
+ }
}
/**
import com.vaadin.terminal.Sizeable;
import com.vaadin.terminal.Terminal;
import com.vaadin.terminal.URIHandler;
+import com.vaadin.terminal.gwt.client.ui.VView;
import com.vaadin.terminal.gwt.client.ui.VWindow;
/**
*/
private boolean centerRequested = false;
+ /**
+ * Should resize recalculate layouts lazily (as opposed to immediately)
+ */
+ private boolean resizeLazy = false;
+
/**
* Component that should be focused after the next repaint. Null if no focus
* change should take place.
if (resizable) {
target.addAttribute("resizable", true);
}
+ if (resizeLazy) {
+ target.addAttribute(VView.RESIZE_LAZY, resizeLazy);
+ }
if (!draggable) {
// Inverted to prevent an extra attribute for almost all sub windows
return resizable;
}
+ /**
+ *
+ * @return true if a delay is used before recalculating sizes, false if
+ * sizes are recalculated immediately.
+ */
+ public boolean isResizeLazy() {
+ return resizeLazy;
+ }
+
+ /**
+ * Should resize operations be lazy, i.e. should there be a delay before
+ * layout sizes are recalculated. Speeds up resize operations in slow UIs
+ * with the penalty of slightly decreased usability.
+ *
+ * Note, some browser send false resize events for the browser window and
+ * are therefore always lazy.
+ *
+ * @param resizeLazy
+ * true to use a delay before recalculating sizes, false to
+ * calculate immediately.
+ */
+ public void setResizeLazy(boolean resizeLazy) {
+ this.resizeLazy = resizeLazy;
+ requestRepaint();
+ }
+
/**
* Request to center this window on the screen. <b>Note:</b> affects
* sub-windows only.
--- /dev/null
+package com.vaadin.tests.components.window;
+
+import com.vaadin.tests.components.AbstractTestCase;
+import com.vaadin.tests.util.LoremIpsum;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Window;
+
+public class LazyWindowResize extends AbstractTestCase {
+
+ private Window mainWindow;
+ private Window subWindow;
+ private Button lazyMode;
+
+ @Override
+ protected String getDescription() {
+ return "Check or uncheck the checkbox to use lazy or eager resize events. Lazy mode uses a small delay before recalculating layout sizes and can be used to speed up resizes in slow UIs.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 6715;
+ }
+
+ @Override
+ public void init() {
+ mainWindow = new Window("Resize test");
+ setMainWindow(mainWindow);
+ subWindow = new Window("Sub window");
+ subWindow.setHeight("50%");
+ subWindow.setWidth("50%");
+ subWindow.center();
+ subWindow.addComponent(new Label(LoremIpsum.get(1000)));
+ getMainWindow().addWindow(subWindow);
+
+ lazyMode = new CheckBox("Lazy resize");
+ lazyMode.setImmediate(true);
+ lazyMode.addListener(new ClickListener() {
+
+ public void buttonClick(ClickEvent event) {
+ setLazy(lazyMode.booleanValue());
+ }
+ });
+ mainWindow.addComponent(lazyMode);
+ mainWindow.addComponent(new Label("<br/><br/>", Label.CONTENT_XHTML));
+ mainWindow.addComponent(new Label(LoremIpsum.get(10000)));
+
+ setLazy(false);
+ }
+
+ private void setLazy(boolean b) {
+ mainWindow.setResizeLazy(b);
+ subWindow.setResizeLazy(b);
+ }
+
+}