Procházet zdrojové kódy

Form without own measuring (#8313)

tags/7.0.0.alpha2
Leif Åstrand před 12 roky
rodič
revize
a280d19e6e

+ 7
- 0
WebContent/VAADIN/themes/base/common/common.css Zobrazit soubor

@@ -90,7 +90,14 @@ div.v-app-loading {
border: none;
padding: 0;
margin: 0;
height: 100%;
}
.v-form-content {
height: 100%;
box-sizing: border-box;
-moz-box-sizing: border-box;
}

/* Field modified */ /* Disabled by default
.v-modified,
.v-richtextarea.v-modified iframe.gwt-RichTextArea,

+ 2
- 128
src/com/vaadin/terminal/gwt/client/ui/VForm.java Zobrazit soubor

@@ -4,8 +4,6 @@

package com.vaadin.terminal.gwt.client.ui;

import java.util.Set;

import com.google.gwt.dom.client.Style.Display;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.event.dom.client.KeyDownHandler;
@@ -16,21 +14,12 @@ import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.Container;
import com.vaadin.terminal.gwt.client.RenderInformation;
import com.vaadin.terminal.gwt.client.RenderSpace;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VConsole;
import com.vaadin.terminal.gwt.client.VErrorMessage;

public class VForm extends ComplexPanel implements Container, KeyDownHandler {
public class VForm extends ComplexPanel implements KeyDownHandler {

protected String id;

private String height = "";

private String width = "";

public static final String CLASSNAME = "v-form";

Widget lo;
@@ -51,12 +40,6 @@ public class VForm extends ComplexPanel implements Container, KeyDownHandler {

ApplicationConnection client;

private RenderInformation renderInformation = new RenderInformation();

private int borderPaddingHorizontal = -1;

boolean rendering = false;

ShortcutActionHandler shortcutHandler;

HandlerRegistration keyDownRegistration;
@@ -74,6 +57,7 @@ public class VForm extends ComplexPanel implements Container, KeyDownHandler {
fieldSet.appendChild(desc); // Adding description for initial padding
// measurements, removed later if no
// description is set
fieldContainer.setClassName(CLASSNAME + "-content");
fieldSet.appendChild(fieldContainer);
errorMessage.setVisible(false);
errorMessage.setStyleName(CLASSNAME + "-errormessage");
@@ -81,116 +65,6 @@ public class VForm extends ComplexPanel implements Container, KeyDownHandler {
fieldSet.appendChild(footerContainer);
}

public void updateSize() {

renderInformation.updateSize(getElement());

renderInformation.setContentAreaHeight(renderInformation
.getRenderedSize().getHeight() - getSpaceConsumedVertically());
renderInformation.setContentAreaWidth(renderInformation
.getRenderedSize().getWidth() - borderPaddingHorizontal);
}

public RenderSpace getAllocatedSpace(Widget child) {
if (child == lo) {
return renderInformation.getContentAreaSize();
} else if (child == footer) {
return new RenderSpace(renderInformation.getContentAreaSize()
.getWidth(), 0);
} else {
VConsole.error("Invalid child requested RenderSpace information");
return null;
}
}

public boolean hasChildComponent(Widget component) {
return component != null && (component == lo || component == footer);
}

public void replaceChildComponent(Widget oldComponent, Widget newComponent) {
if (!hasChildComponent(oldComponent)) {
throw new IllegalArgumentException(
"Old component is not inside this Container");
}
remove(oldComponent);
if (oldComponent == lo) {
lo = newComponent;
add(newComponent, fieldContainer);
} else {
footer = newComponent;
add(newComponent, footerContainer);
}

}

public boolean requestLayout(Set<Widget> child) {

if (height != null && !"".equals(height) && width != null
&& !"".equals(width)) {
/*
* If the height and width has been specified the child components
* cannot make the size of the layout change
*/

return true;
}

if (renderInformation.updateSize(getElement())) {
return false;
} else {
return true;
}

}

@Override
public void setHeight(String height) {
if (this.height.equals(height)) {
return;
}

this.height = height;
super.setHeight(height);

updateSize();
}

/**
* @return pixels consumed by decoration, captions, descrioptiosn etc.. In
* other words space, not used by the actual layout in form.
*/
private int getSpaceConsumedVertically() {
int offsetHeight2 = fieldSet.getOffsetHeight();
int offsetHeight3 = fieldContainer.getOffsetHeight();
int borderPadding = offsetHeight2 - offsetHeight3;
return borderPadding;
}

@Override
public void setWidth(String width) {
if (borderPaddingHorizontal < 0) {
// measure excess size lazily after stylename setting, but before
// setting width
int ow = getOffsetWidth();
int dow = desc.getOffsetWidth();
borderPaddingHorizontal = ow - dow;
}
if (Util.equals(this.width, width)) {
return;
}

this.width = width;
super.setWidth(width);

updateSize();

if (!rendering && height.equals("")) {
// Width might affect height
Util.updateRelativeChildrenAndSendSizeUpdateEvent(client, this,
this);
}
}

public void onKeyDown(KeyDownEvent event) {
shortcutHandler.handleKeyboardEvent(Event.as(event.getNativeEvent()));
}

+ 20
- 12
src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java Zobrazit soubor

@@ -4,14 +4,23 @@
package com.vaadin.terminal.gwt.client.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.MeasuredSize;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.VPaintableMap;
import com.vaadin.terminal.gwt.client.VPaintableWidget;

public class VFormPaintable extends VAbstractPaintableWidgetContainer {
public class VFormPaintable extends VAbstractPaintableWidgetContainer implements
ResizeRequired {

public VFormPaintable() {
VForm form = getWidgetForPaintable();
MeasuredSize measuredSize = getMeasuredSize();
measuredSize.registerDependency(form.footerContainer);
}

@Override
protected boolean delegateCaptionHandling() {
@@ -20,13 +29,11 @@ public class VFormPaintable extends VAbstractPaintableWidgetContainer {

@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
getWidgetForPaintable().rendering = true;
getWidgetForPaintable().client = client;
getWidgetForPaintable().id = uidl.getId();

super.updateFromUIDL(uidl, client);
if (!isRealUpdate(uidl)) {
getWidgetForPaintable().rendering = false;
return;
}

@@ -83,8 +90,6 @@ public class VFormPaintable extends VAbstractPaintableWidgetContainer {
}
}

getWidgetForPaintable().updateSize();

// first render footer so it will be easier to handle relative height of
// main layout
if (uidl.getChildCount() > 1
@@ -106,15 +111,11 @@ public class VFormPaintable extends VAbstractPaintableWidgetContainer {
}
getWidgetForPaintable().footer = newFooterWidget;
newFooter.updateFromUIDL(uidl.getChildUIDL(1), client);
// needed for the main layout to know the space it has available
getWidgetForPaintable().updateSize();
} else {
if (getWidgetForPaintable().footer != null) {
getWidgetForPaintable().remove(getWidgetForPaintable().footer);
client.unregisterPaintable(VPaintableMap.get(getConnection())
.getPaintable(getWidgetForPaintable().footer));
// needed for the main layout to know the space it has available
getWidgetForPaintable().updateSize();
}
}

@@ -139,7 +140,6 @@ public class VFormPaintable extends VAbstractPaintableWidgetContainer {

// also recalculates size of the footer if undefined size form - see
// #3710
getWidgetForPaintable().updateSize();
client.runDescendentsLayout(getWidgetForPaintable());

// We may have actions attached
@@ -161,8 +161,6 @@ public class VFormPaintable extends VAbstractPaintableWidgetContainer {
getWidgetForPaintable().shortcutHandler = null;
getWidgetForPaintable().keyDownRegistration = null;
}

getWidgetForPaintable().rendering = false;
}

public void updateCaption(VPaintableWidget component, UIDL uidl) {
@@ -180,4 +178,14 @@ public class VFormPaintable extends VAbstractPaintableWidgetContainer {
return GWT.create(VForm.class);
}

public void onResize() {
MeasuredSize measuredSize = getMeasuredSize();
VForm form = getWidgetForPaintable();

int footerHeight = measuredSize
.getDependencyOuterHeight(form.footerContainer);
form.fieldContainer.getStyle().setPaddingBottom(footerHeight, Unit.PX);
form.footerContainer.getStyle().setMarginTop(-footerHeight, Unit.PX);
}

}

Načítá se…
Zrušit
Uložit