Sfoglia il codice sorgente

Communicate component width and height only via shared state (#8304).

Also removes old fix for #4608, needs to be redesigned together with
layout changes.
tags/7.0.0.alpha2
Henri Sara 12 anni fa
parent
commit
bc8914066b

+ 15
- 9
src/com/vaadin/terminal/gwt/client/Util.java Vedi File

@@ -32,6 +32,7 @@ import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.RenderInformation.FloatSize;
import com.vaadin.terminal.gwt.client.communication.MethodInvocation;
import com.vaadin.terminal.gwt.client.communication.SharedState;

public class Util {

@@ -563,25 +564,30 @@ public class Util {
}

/**
* Parses the UIDL parameter and fetches the relative size of the component.
* If a dimension is not specified as relative it will return -1. If the
* UIDL does not contain width or height specifications this will return
* Parses shared state and fetches the relative size of the component. If a
* dimension is not specified as relative it will return -1. If the shared
* state does not contain width or height specifications this will return
* null.
*
* @param uidl
* @param state
* @return
*/
public static FloatSize parseRelativeSize(UIDL uidl) {
public static FloatSize parseRelativeSize(SharedState state) {
if (null == state) {
return null;
}

boolean hasAttribute = false;
String w = "";
String h = "";
if (uidl.hasAttribute("width")) {
Map<String, Object> stateMap = state.getState();
if (stateMap.containsKey("width")) {
hasAttribute = true;
w = uidl.getStringAttribute("width");
w = String.valueOf(stateMap.get("width"));
}
if (uidl.hasAttribute("height")) {
if (stateMap.containsKey("height")) {
hasAttribute = true;
h = uidl.getStringAttribute("height");
h = String.valueOf(stateMap.get("height"));
}

if (!hasAttribute) {

+ 3
- 1
src/com/vaadin/terminal/gwt/client/VUIDLBrowser.java Vedi File

@@ -46,7 +46,9 @@ public class VUIDLBrowser extends SimpleTree {
}
Set<String> keySet = u.getKeySet();
for (String key : keySet) {
if (key.equals("changes")) {
if (key.equals("state")) {
// TODO print updated shared states
} else if (key.equals("changes")) {
JsArray<UIDL> jsValueMapArray = u.getJSValueMapArray("changes")
.cast();
for (int i = 0; i < jsValueMapArray.length(); i++) {

+ 4
- 0
src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java Vedi File

@@ -151,6 +151,10 @@ public abstract class VAbstractPaintableWidget implements VPaintableWidget {
return;
}

if (!isRealUpdate(uidl)) {
return;
}

/*
* Disabled state may affect (override) tabindex so the order must be
* first setting tabindex, then enabled state.

+ 17
- 11
src/com/vaadin/terminal/gwt/client/ui/VEmbeddedPaintable.java Vedi File

@@ -20,6 +20,7 @@ import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.ComponentState;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.VConsole;
import com.vaadin.terminal.gwt.client.VTooltip;
@@ -69,18 +70,23 @@ public class VEmbeddedPaintable extends VAbstractPaintableWidget {

// Set attributes
Style style = el.getStyle();
String w = uidl.getStringAttribute("width");
if (w != null) {
style.setProperty("width", w);
} else {
style.setProperty("width", "");
}
String h = uidl.getStringAttribute("height");
if (h != null) {
style.setProperty("height", h);
} else {
style.setProperty("height", "");
String w = "";
String h = "";
if (null != getState()) {
if (getState().getState().containsKey(
ComponentState.STATE_WIDTH)) {
w = String.valueOf(getState().getState().get(
ComponentState.STATE_WIDTH));
}
if (getState().getState().containsKey(
ComponentState.STATE_HEIGHT)) {
h = String.valueOf(getState().getState().get(
ComponentState.STATE_HEIGHT));
}
}
style.setProperty("width", w);
style.setProperty("height", h);

DOM.setElementProperty(el, "src", getWidgetForPaintable()
.getSrc(uidl, client));


+ 15
- 10
src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java Vedi File

@@ -26,6 +26,7 @@ import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VPaintableMap;
import com.vaadin.terminal.gwt.client.VPaintableWidget;
import com.vaadin.terminal.gwt.client.communication.SharedState;
import com.vaadin.terminal.gwt.client.ui.layout.CellBasedLayout;
import com.vaadin.terminal.gwt.client.ui.layout.ChildComponentContainer;

@@ -928,25 +929,29 @@ public class VGridLayout extends SimplePanel implements Container {
}
}
childUidl = c;
updateRelSizeStatus(c);
updateRelSizeStatus(client.getPaintable(c).getState(),
c.getBooleanAttribute("cached"));
}

protected void updateRelSizeStatus(UIDL uidl) {
if (uidl != null && !uidl.getBooleanAttribute("cached")) {
if (uidl.hasAttribute("height")
&& uidl.getStringAttribute("height").contains("%")) {
protected void updateRelSizeStatus(SharedState state, boolean cached) {
if (state != null && !cached) {
boolean widthDefined = state.getState().containsKey("width");
boolean heightDefined = state.getState().containsKey("height");
if (heightDefined
&& String.valueOf(state.getState().get("height"))
.contains("%")) {
relHeight = true;
} else {
relHeight = false;
}
if (uidl.hasAttribute("width")) {
widthCanAffectHeight = relWidth = uidl.getStringAttribute(
"width").contains("%");
if (uidl.hasAttribute("height")) {
if (widthDefined) {
widthCanAffectHeight = relWidth = String.valueOf(
state.getState().get("width")).contains("%");
if (heightDefined) {
widthCanAffectHeight = false;
}
} else {
widthCanAffectHeight = !uidl.hasAttribute("height");
widthCanAffectHeight = !heightDefined;
relWidth = false;
}
}

+ 2
- 1
src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java Vedi File

@@ -175,8 +175,9 @@ public class VGridLayoutPaintable extends VAbstractPaintableWidgetContainer {
}
if (!getWidgetForPaintable().rendering) {
// ensure rel size details are updated
boolean cached = uidl.getBooleanAttribute("cached");
getWidgetForPaintable().widgetToCell.get(widget)
.updateRelSizeStatus(uidl);
.updateRelSizeStatus(paintable.getState(), cached);
/*
* This was a component-only update and the possible size change
* must be propagated to the layout

+ 4
- 1
src/com/vaadin/terminal/gwt/client/ui/VMenuBarPaintable.java Vedi File

@@ -10,6 +10,7 @@ import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.ComponentState;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.ui.VMenuBar.CustomMenuItem;
@@ -50,7 +51,9 @@ public class VMenuBarPaintable extends VAbstractPaintableWidget {

UIDL options = uidl.getChildUIDL(0);

if (uidl.hasAttribute("width")) {
if (null != getState()
&& getState().getState()
.containsKey(ComponentState.STATE_WIDTH)) {
UIDL moreItemUIDL = options.getChildUIDL(0);
StringBuffer itemHTML = new StringBuffer();


+ 3
- 2
src/com/vaadin/terminal/gwt/client/ui/VOrderedLayoutPaintable.java Vedi File

@@ -105,8 +105,9 @@ public abstract class VOrderedLayoutPaintable extends CellBasedLayoutPaintable {
* the layout are rendered later when it is clear how much space
* they can use
*/
if (isRealUpdate(childUIDL)) {
FloatSize relativeSize = Util.parseRelativeSize(childUIDL);
if (null != childPaintable.getState()) {
FloatSize relativeSize = Util.parseRelativeSize(childPaintable
.getState());
childComponentContainer.setRelativeSize(relativeSize);
}


+ 13
- 2
src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java Vedi File

@@ -3,6 +3,8 @@
*/
package com.vaadin.terminal.gwt.client.ui;

import java.util.Map;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.DomEvent.Type;
import com.google.gwt.event.shared.EventHandler;
@@ -13,6 +15,7 @@ import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.ComponentState;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VPaintableWidget;
@@ -151,8 +154,16 @@ public class VWindowPaintable extends VAbstractPaintableWidgetContainer
getWidgetForPaintable().layout = lo;
}

getWidgetForPaintable().dynamicWidth = !uidl.hasAttribute("width");
getWidgetForPaintable().dynamicHeight = !uidl.hasAttribute("height");
if (null != getState()) {
Map<String, Object> state = getState().getState();
getWidgetForPaintable().dynamicWidth = !state
.containsKey(ComponentState.STATE_WIDTH);
getWidgetForPaintable().dynamicHeight = !state
.containsKey(ComponentState.STATE_HEIGHT);
} else {
getWidgetForPaintable().dynamicWidth = true;
getWidgetForPaintable().dynamicHeight = true;
}

getWidgetForPaintable().layoutRelativeWidth = uidl
.hasAttribute("layoutRelativeWidth");

+ 15
- 7
src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayoutPaintable.java Vedi File

@@ -4,6 +4,7 @@
package com.vaadin.terminal.gwt.client.ui.layout;

import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.ComponentState;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.ui.VAbstractPaintableWidgetContainer;
import com.vaadin.terminal.gwt.client.ui.VMarginInfo;
@@ -31,16 +32,23 @@ public abstract class CellBasedLayoutPaintable extends
super.updateFromUIDL(uidl, client);

if (isRealUpdate(uidl)) {
handleDynamicDimensions(uidl);
handleDynamicDimensions();
}
}

private void handleDynamicDimensions(UIDL uidl) {
String w = uidl.hasAttribute("width") ? uidl
.getStringAttribute("width") : "";

String h = uidl.hasAttribute("height") ? uidl
.getStringAttribute("height") : "";
private void handleDynamicDimensions() {
String w = "";
String h = "";
if (null != getState()) {
if (getState().getState().containsKey(ComponentState.STATE_WIDTH)) {
w = String.valueOf(getState().getState().get(
ComponentState.STATE_WIDTH));
}
if (getState().getState().containsKey(ComponentState.STATE_HEIGHT)) {
h = String.valueOf(getState().getState().get(
ComponentState.STATE_HEIGHT));
}
}

if (w.equals("")) {
getWidgetForPaintable().dynamicWidth = true;

+ 0
- 12
src/com/vaadin/terminal/gwt/client/ui/layout/ChildComponentContainer.java Vedi File

@@ -438,18 +438,6 @@ public class ChildComponentContainer extends Panel {
}

updateCaptionSize();

if (relativeSize == null) {
/*
* relativeSize may be null if component is updated via independent
* update, after it has initially been hidden. See #4608
*
* It might also change in which case there would be similar issues.
*
* Yes, it is an ugly hack. Don't come telling me about it.
*/
setRelativeSize(Util.parseRelativeSize(uidl));
}
}

public void updateCaptionSize() {

+ 3
- 10
src/com/vaadin/ui/AbstractComponent.java Vedi File

@@ -768,17 +768,8 @@ public abstract class AbstractComponent implements Component, MethodEventSource

// Only paint content of visible components.
if (isVisible()) {
if (getHeight() >= 0
&& (getHeightUnits() != Unit.PERCENTAGE || ComponentSizeValidator
.parentCanDefineHeight(this))) {
target.addAttribute("height", "" + getCSSHeight());
}
// width and height are only in shared state

if (getWidth() >= 0
&& (getWidthUnits() != Unit.PERCENTAGE || ComponentSizeValidator
.parentCanDefineWidth(this))) {
target.addAttribute("width", "" + getCSSWidth());
}
if (styles != null && styles.size() > 0) {
target.addAttribute("style", getStyle());
}
@@ -902,6 +893,8 @@ public abstract class AbstractComponent implements Component, MethodEventSource
state.put(ComponentState.STATE_WIDTH, "" + getCSSWidth());
}

// TODO use the rest on the client side

if (styles != null && styles.size() > 0) {
state.put(ComponentState.STATE_STYLE, getStyle());
}

Loading…
Annulla
Salva