public static int measureHorizontalBorder(Element element) {
int borders;
- if (BrowserInfo.get().isIE6()) {
- String originalWidth = DOM.getStyleAttribute(element, "width");
- int originalOffsetWidth = element.getOffsetWidth();
- if (originalOffsetWidth < 1) {
- originalOffsetWidth = 10;
+ if (BrowserInfo.get().isIE()) {
+ String width = element.getStyle().getProperty("width");
+ String height = element.getStyle().getProperty("height");
+
+ int offsetWidth = element.getOffsetWidth();
+ int offsetHeight = element.getOffsetHeight();
+ if (BrowserInfo.get().isIE6()) {
+ if (offsetHeight < 1) {
+ offsetHeight = 1;
+ }
+ if (offsetWidth < 1) {
+ offsetWidth = 10;
+ }
+ element.getStyle().setPropertyPx("height", offsetHeight);
}
+ element.getStyle().setPropertyPx("width", offsetWidth);
- DOM.setStyleAttribute(element, "width", originalOffsetWidth + "px");
- int cw = element.getPropertyInt("clientWidth");
- borders = element.getOffsetWidth() - cw;
+ borders = element.getOffsetWidth()
+ - element.getPropertyInt("clientWidth");
- DOM.setStyleAttribute(element, "width", originalWidth);
+ element.getStyle().setProperty("width", width);
+ if (BrowserInfo.get().isIE6()) {
+ element.getStyle().setProperty("height", height);
+ }
} else {
borders = element.getOffsetWidth()
- element.getPropertyInt("clientWidth");
import java.util.Iterator;
import java.util.Set;
+import com.google.gwt.dom.client.Style;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.DeferredCommand;
}
}
+ private boolean isDynamicWidth() {
+ return width == null || width.equals("");
+ }
+
public ITabsheet() {
super(CLASSNAME);
}
// tabs; push or not
- if (uidl.hasAttribute("width")) {
+ if (!isDynamicWidth()) {
// update width later, in updateTabScroller();
DOM.setStyleAttribute(tabs, "width", "1px");
DOM.setStyleAttribute(tabs, "overflow", "hidden");
showAllTabs();
DOM.setStyleAttribute(tabs, "width", "");
DOM.setStyleAttribute(tabs, "overflow", "visible");
+ updateDynamicWidth();
}
updateTabScroller();
waitingForResponse = false;
}
+ private void updateDynamicWidth() {
+ // Find tab width
+ int tabsWidth = 0;
+
+ int count = tb.getTabCount();
+ for (int i = 0; i < count; i++) {
+ Element tabTd = tb.getTab(i).getElement().getParentElement().cast();
+ tabsWidth += tabTd.getOffsetWidth();
+ }
+
+ // Find content width
+ Style style = tp.getElement().getStyle();
+ String overflow = style.getProperty("overflow");
+ style.setProperty("overflow", "hidden");
+ String width = style.getProperty("width");
+ style.setProperty("width", tabsWidth + "px");
+ // Get content width from actual widget
+ int contentWidth = tp.getWidget(tp.getVisibleWidget()).getOffsetWidth();
+ style.setProperty("width", width);
+ style.setProperty("overflow", overflow);
+
+ // Set widths to max(tabs,content)
+ if (tabsWidth < contentWidth) {
+ tabsWidth = contentWidth;
+ }
+
+ tabs.getStyle().setPropertyPx("width", tabsWidth);
+
+ /*
+ * tb width includes the spacerTd width so the content area will be as
+ * wide as the tab bar
+ */
+ int realWidth = tb.getOffsetWidth();
+ contentWidth = realWidth - getContentAreaBorderWidth();
+
+ contentNode.getStyle().setPropertyPx("width", contentWidth);
+ super.setWidth(realWidth + "px");
+ }
+
protected void renderTab(final UIDL tabUidl, int index, boolean selected) {
ICaption c = tb.getTab(index);
if (c == null) {
public void setWidth(String width) {
super.setWidth(width);
+ if (width.equals("")) {
+ width = null;
+ }
this.width = width;
- if ("".equals(width)) {
+ if (width == null) {
renderSpace.setWidth(0);
contentNode.getStyle().setProperty("width", "");
} else {
int contentWidth = getOffsetWidth() - getContentAreaBorderWidth();
+ if (contentWidth < 0) {
+ contentWidth = 0;
+ }
contentNode.getStyle().setProperty("width", contentWidth + "px");
renderSpace.setWidth(contentWidth);
}
private int borderW = -1;
- private void detectBorder() {
- String property = contentNode.getStyle().getProperty("overflow");
- contentNode.getStyle().setProperty("overflow", "hidden");
- borderW = contentNode.getOffsetWidth()
- - contentNode.getPropertyInt("clientWidth");
- contentNode.getStyle().setProperty("overflow", property);
- }
-
private int getContentAreaBorderWidth() {
if (borderW < 0) {
- detectBorder();
+ borderW = Util.measureHorizontalBorder(contentNode);
}
return borderW;
}
--- /dev/null
+package com.itmill.toolkit.tests.tickets;
+
+import com.itmill.toolkit.Application;
+import com.itmill.toolkit.ui.Button;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.TabSheet;
+import com.itmill.toolkit.ui.Window;
+
+public class Ticket2180 extends Application {
+
+ private Window mainWindow;
+ private TabSheet tabSheet;
+
+ @Override
+ public void init() {
+ mainWindow = new Window("Tabsheet should cause scrollbars");
+ setMainWindow(mainWindow);
+ // mainWindow.getLayout().setSizeFull();
+ tabSheet = new TabSheet();
+ // tabSheet.setWidth("100%");
+ Button button = new Button("Blah");
+ button.setWidth("100%");
+ Label label1 = new Label("Lorem ipsum");
+ Label label2 = new Label("Lorem");
+ Label label3 = new Label(
+ "Lorema jsdfhak sjdfh kajsdh fkajhd kfjah dkfjah ksfdjh kajsfh kj 1 2 3 4 5 6 7 8 9 10");
+
+ label3.setWidth("800px");
+ tabSheet.addTab(label1, "Tab 1", null);
+ tabSheet.addTab(label2, "Tab 2", null);
+ tabSheet.addTab(label3, "Tab 3", null);
+ tabSheet.addTab(new Label("a"), "Tab 4", null);
+ tabSheet.addTab(new Label("a"), "Tab 5", null);
+ tabSheet.addTab(new Label("a"), "Tab 6", null);
+ // mainWindow.addComponent(new Label("123"));
+ mainWindow.addComponent(tabSheet);
+ mainWindow.addComponent(button);
+ // mainWindow.addComponent(new Label("abc"));
+ }
+
+}