height = uidl.hasVariable("height") ? uidl.getStringVariable("height")
: null;
setWidth(w != null ? w : "");
+ setHeight(height != null ? height : "");
// TODO optimize: if only the caption has changed, don't re-render whole
// content
public void iLayout() {
// In this case we need to fix containers height properly
if (height != null && height != "") {
- // First, calculate needed pixel height
- setHeight(height);
- int neededHeight = getOffsetHeight();
- setHeight("");
- // Then calculate the size the content area needs to be
- DOM.setStyleAttribute(contentNode, "height", "0");
- DOM.setStyleAttribute(contentNode, "overflow", "hidden");
- int h = getOffsetHeight();
- int total = neededHeight - h;
- if (total < 0)
- total = 0;
- DOM.setStyleAttribute(contentNode, "height", total + "px");
- DOM.setStyleAttribute(contentNode, "overflow", "");
- } else {
+ // need to fix containers height properly
+
+ boolean hasChildren = getWidget() != null;
+ Element contentEl = null;
+ String origPositioning = null;
+ if (hasChildren) {
+ // remove children temporary form normal flow to detect proper
+ // size
+ contentEl = getWidget().getElement();
+ origPositioning = DOM.getStyleAttribute(contentEl, "position");
+ DOM.setStyleAttribute(contentEl, "position", "absolute");
+ }
DOM.setStyleAttribute(contentNode, "height", "");
- // We don't need overflow:auto when height is not set
+ int availableH = DOM.getElementPropertyInt(getElement(),
+ "clientHeight");
+
+ int usedH = DOM
+ .getElementPropertyInt(bottomDecoration, "offsetTop")
+ + DOM.getElementPropertyInt(bottomDecoration,
+ "offsetHeight");
+ int contentH = availableH - usedH;
+ if (contentH < 0)
+ contentH = 0;
+ DOM.setStyleAttribute(contentNode, "height", contentH + "px");
+ if (hasChildren) {
+ DOM.setStyleAttribute(contentEl, "position", origPositioning);
+ }
+ DOM.setStyleAttribute(contentNode, "overflow", "auto");
+ } else {
DOM.setStyleAttribute(contentNode, "overflow", "hidden");
}
Util.runAnchestorsLayout(this);
HeaderCell cell = tHead.getHeaderCell(colIndex);
cell.setWidth(w);
tBody.setColWidth(colIndex, w);
- String cid = cell.getColKey();
- ;
}
private int getColWidth(String colKey) {
return null;
}
- private int getRenderedRowCount() {
- return tBody.getLastRendered() - tBody.getFirstRendered();
- }
-
private void reOrderColumn(String columnKey, int newIndex) {
int oldIndex = getColIndexByKey(columnKey);
public void iLayout() {
if (height != null) {
+
+ if(height.equals("100%")) {
+ // we define height in pixels with 100% not to include borders
+ setHeight(height);
+ }
+
int contentH = (DOM.getElementPropertyInt(getElement(),
"clientHeight") - tHead.getOffsetHeight());
if (contentH < 0)
return panel.remove(w);
}
+ public void setHeight(String height) {
+ // workaround very common 100% height problem - extract borders
+ if(height.equals("100%")) {
+ final int borders = getBorderSpace();
+ Element elem = getElement();
+ Element parentElem = DOM.getParent(elem);
+
+ // put table away from flow for a moment
+ DOM.setStyleAttribute(getElement(), "position", "absolute");
+ // get containers natural space for table
+ int availPixels = DOM.getElementPropertyInt(parentElem, "clientHeight");
+ // put table back to flow
+ DOM.setStyleAttribute(getElement(), "position", "static");
+ // set 100% height with borders
+ super.setHeight((availPixels - borders) + "px");
+ } else {
+ // normally height don't include borders
+ super.setHeight(height);
+ }
+ }
+
+ private int getBorderSpace() {
+ Element el = getElement();
+ return DOM.getElementPropertyInt(el, "offsetHeight") - DOM.getElementPropertyInt(el, "clientHeight");
+ }
+
}
public static final int ORIENTATION_HORIZONTAL = 0;
public static final int ORIENTATION_VERTICAL = 1;
- private static final int SPLITTER_SIZE = 10;
+ private static final int MIN_SIZE = 30;
- private static final String MIN_SIZE = (3 * SPLITTER_SIZE) + "px";
-
- private int orientation;
+ private int orientation = ORIENTATION_HORIZONTAL;
private Widget firstChild;
private Widget secondChild;
}
// size below will be overridden in update from uidl, initial size
// needed to keep IE alive
- setWidth(MIN_SIZE);
- setHeight(MIN_SIZE);
+ setWidth(MIN_SIZE + "px");
+ setHeight(MIN_SIZE + "px");
constructDom();
setOrientation(orientation);
- setSplitPosition("50%");
DOM.sinkEvents(splitter, (Event.MOUSEEVENTS));
DOM.sinkEvents(getElement(), (Event.MOUSEEVENTS));
}
protected void constructDom() {
+ DOM.appendChild(splitter, DOM.createDiv()); // for styling
DOM.appendChild(getElement(), wrapper);
DOM.setStyleAttribute(wrapper, "position", "relative");
DOM.setStyleAttribute(wrapper, "width", "100%");
this.orientation = orientation;
if (orientation == ORIENTATION_HORIZONTAL) {
DOM.setStyleAttribute(splitter, "height", "100%");
- DOM.setStyleAttribute(splitter, "width", SPLITTER_SIZE + "px");
DOM.setStyleAttribute(firstContainer, "height", "100%");
DOM.setStyleAttribute(secondContainer, "height", "100%");
} else {
DOM.setStyleAttribute(splitter, "width", "100%");
- DOM.setStyleAttribute(splitter, "height", SPLITTER_SIZE + "px");
DOM.setStyleAttribute(firstContainer, "width", "100%");
DOM.setStyleAttribute(secondContainer, "width", "100%");
}
}
int wholeSize;
int pixelPosition;
- ApplicationConnection.getConsole().log("splitterpaneeeli");
switch (orientation) {
case ORIENTATION_HORIZONTAL:
pixelPosition = DOM.getElementPropertyInt(splitter, "offsetLeft");
// reposition splitter in case it is out of box
- if (pixelPosition + SPLITTER_SIZE > wholeSize) {
- pixelPosition = wholeSize - SPLITTER_SIZE;
+ if (pixelPosition > 0 && pixelPosition + getSplitterSize() > wholeSize) {
+ pixelPosition = wholeSize - getSplitterSize();
+ if (pixelPosition < 0)
+ pixelPosition = 0;
setSplitPosition(pixelPosition + "px");
return;
}
DOM
.setStyleAttribute(firstContainer, "width", pixelPosition
+ "px");
- int secondContainerWidth = (wholeSize - pixelPosition - SPLITTER_SIZE);
+ int secondContainerWidth = (wholeSize - pixelPosition - getSplitterSize());
if (secondContainerWidth < 0)
secondContainerWidth = 0;
DOM.setStyleAttribute(secondContainer, "width",
secondContainerWidth + "px");
DOM.setStyleAttribute(secondContainer, "left",
- (pixelPosition + SPLITTER_SIZE) + "px");
+ (pixelPosition + getSplitterSize()) + "px");
break;
case ORIENTATION_VERTICAL:
pixelPosition = DOM.getElementPropertyInt(splitter, "offsetTop");
// reposition splitter in case it is out of box
- if (pixelPosition + SPLITTER_SIZE > wholeSize) {
- pixelPosition = wholeSize - SPLITTER_SIZE;
+ if (pixelPosition > 0 && pixelPosition + getSplitterSize() > wholeSize) {
+ pixelPosition = wholeSize - getSplitterSize();
+ if (pixelPosition < 0)
+ pixelPosition = 0;
setSplitPosition(pixelPosition + "px");
return;
}
DOM.setStyleAttribute(firstContainer, "height", pixelPosition
+ "px");
- int secondContainerHeight = (wholeSize - pixelPosition - SPLITTER_SIZE);
+ int secondContainerHeight = (wholeSize - pixelPosition - getSplitterSize());
if (secondContainerHeight < 0)
secondContainerHeight = 0;
DOM.setStyleAttribute(secondContainer, "height",
secondContainerHeight + "px");
DOM.setStyleAttribute(secondContainer, "top",
- (pixelPosition + SPLITTER_SIZE) + "px");
+ (pixelPosition + getSplitterSize()) + "px");
+ break;
default:
ApplicationConnection.getConsole().log("???");
super.setHeight(height);
// give sane height
getOffsetHeight(); // shake IE
- if (getOffsetHeight() < SPLITTER_SIZE)
- super.setHeight((SPLITTER_SIZE * 3) + "px");
+ if (getOffsetHeight() < MIN_SIZE)
+ super.setHeight(MIN_SIZE + "px");
}
public void setWidth(String width) {
super.setWidth(width);
// give sane width
getOffsetWidth(); // shake IE
- if (getOffsetWidth() < SPLITTER_SIZE)
- super.setWidth((SPLITTER_SIZE * 3) + "px");
+ if (getOffsetWidth() < MIN_SIZE)
+ super.setWidth(MIN_SIZE + "px");
}
public void onBrowserEvent(Event event) {
int newX = origX + x - origMouseX;
if (newX < 0)
newX = 0;
- if (newX + SPLITTER_SIZE > getOffsetWidth())
- newX = getOffsetWidth() - SPLITTER_SIZE;
+ if (newX + getSplitterSize() > getOffsetWidth())
+ newX = getOffsetWidth() - getSplitterSize();
DOM.setStyleAttribute(splitter, "left", newX + "px");
}
if (newY < 0)
newY = 0;
- if (newY + SPLITTER_SIZE > getOffsetHeight())
- newY = getOffsetHeight() - SPLITTER_SIZE;
+ if (newY + getSplitterSize() > getOffsetHeight())
+ newY = getOffsetHeight() - getSplitterSize();
DOM.setStyleAttribute(splitter, "top", newY + "px");
}
onMouseMove(event);
}
+ private static int splitterSize = -1;
+
+ private int getSplitterSize() {
+ if (splitterSize < 0) {
+ if (isAttached()) {
+ splitterSize = DOM.getElementPropertyInt(splitter, "offsetWidth");
+ }
+ }
+ return splitterSize;
+ }
+
}