diff options
author | Artur Signell <artur@vaadin.com> | 2015-07-16 00:20:26 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2015-08-04 18:02:24 +0300 |
commit | f6d075df5207e02b3e96a35943c022c2c2f29bc1 (patch) | |
tree | 362417b7a63831d794fac8c81addbf178d386227 | |
parent | 50e13188aa372b0ad50c7279bcb3f18706897c23 (diff) | |
download | vaadin-framework-f6d075df5207e02b3e96a35943c022c2c2f29bc1.tar.gz vaadin-framework-f6d075df5207e02b3e96a35943c022c2c2f29bc1.zip |
Take margin/border/padding into account when measuring TabSheet (#18471)
Change-Id: Id6fed9155128ed9134b3d4949b80fc605e5ae62f
4 files changed, 145 insertions, 2 deletions
diff --git a/client/src/com/vaadin/client/ComputedStyle.java b/client/src/com/vaadin/client/ComputedStyle.java index b11ba4b26a..1391a84bfe 100644 --- a/client/src/com/vaadin/client/ComputedStyle.java +++ b/client/src/com/vaadin/client/ComputedStyle.java @@ -280,4 +280,55 @@ public class ComputedStyle { return parseFloat(value); }-*/; + /** + * Returns the sum of the top and bottom border width + * + * @since + * @return the sum of the top and bottom border + */ + public double getBorderHeight() { + double borderHeight = getDoubleProperty("borderTopWidth"); + borderHeight += getDoubleProperty("borderBottomWidth"); + + return borderHeight; + } + + /** + * Returns the sum of the left and right border width + * + * @since + * @return the sum of the left and right border + */ + public double getBorderWidth() { + double borderWidth = getDoubleProperty("borderLeftWidth"); + borderWidth += getDoubleProperty("borderRightWidth"); + + return borderWidth; + } + + /** + * Returns the sum of the top and bottom padding + * + * @since + * @return the sum of the top and bottom padding + */ + public double getPaddingHeight() { + double paddingHeight = getDoubleProperty("paddingTop"); + paddingHeight += getDoubleProperty("paddingBottom"); + + return paddingHeight; + } + + /** + * Returns the sum of the top and bottom padding + * + * @since + * @return the sum of the left and right padding + */ + public double getPaddingWidth() { + double paddingWidth = getDoubleProperty("paddingLeft"); + paddingWidth += getDoubleProperty("paddingRight"); + + return paddingWidth; + } } diff --git a/client/src/com/vaadin/client/ui/VTabsheet.java b/client/src/com/vaadin/client/ui/VTabsheet.java index ded9977f5e..e196870348 100644 --- a/client/src/com/vaadin/client/ui/VTabsheet.java +++ b/client/src/com/vaadin/client/ui/VTabsheet.java @@ -61,11 +61,12 @@ import com.google.gwt.user.client.ui.impl.FocusImpl; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.BrowserInfo; import com.vaadin.client.ComponentConnector; +import com.vaadin.client.ComputedStyle; import com.vaadin.client.Focusable; import com.vaadin.client.TooltipInfo; -import com.vaadin.client.WidgetUtil; import com.vaadin.client.VCaption; import com.vaadin.client.VTooltip; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.aria.AriaHelper; import com.vaadin.shared.AbstractComponentState; import com.vaadin.shared.ComponentConstants; @@ -1227,8 +1228,13 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware public void updateContentNodeHeight() { if (!isDynamicHeight()) { int contentHeight = getOffsetHeight(); - contentHeight -= DOM.getElementPropertyInt(deco, "offsetHeight"); + contentHeight -= deco.getOffsetHeight(); contentHeight -= tb.getOffsetHeight(); + + ComputedStyle cs = new ComputedStyle(contentNode); + contentHeight -= Math.ceil(cs.getPaddingHeight()); + contentHeight -= Math.ceil(cs.getBorderHeight()); + if (contentHeight < 0) { contentHeight = 0; } diff --git a/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetInSplitPanel.java b/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetInSplitPanel.java new file mode 100644 index 0000000000..b2313020a3 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetInSplitPanel.java @@ -0,0 +1,43 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.tabsheet; + +import com.vaadin.annotations.Theme; +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.Label; +import com.vaadin.ui.TabSheet; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalSplitPanel; +import com.vaadin.ui.themes.ValoTheme; + +@Theme("valo") +public class TabSheetInSplitPanel extends UI { + + @Override + protected void init(VaadinRequest request) { + VerticalSplitPanel verticalSplitter = new VerticalSplitPanel(); + setContent(verticalSplitter); + verticalSplitter.setSizeFull(); + TabSheet t = new TabSheet(); + t.setHeight("100%"); + t.addTab(new Label("Hello in tab"), "Hello tab"); + t.setStyleName(ValoTheme.TABSHEET_FRAMED); + verticalSplitter.addComponent(t); + verticalSplitter.addComponent(new Label("Hello")); + + } + +} diff --git a/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetInSplitPanelTest.java b/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetInSplitPanelTest.java new file mode 100644 index 0000000000..8070133bde --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetInSplitPanelTest.java @@ -0,0 +1,43 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.tabsheet; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.TabSheetElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TabSheetInSplitPanelTest extends MultiBrowserTest { + + @Test + public void ensureNoScrollbars() { + openTestURL(); + TabSheetElement ts = $(TabSheetElement.class).first(); + List<WebElement> scrollables = ts.findElements(By + .xpath("//*[contains(@class,'v-scrollable')]")); + for (WebElement scrollable : scrollables) { + assertNoHorizontalScrollbar(scrollable, + "Element should not have a horizontal scrollbar"); + assertNoVerticalScrollbar(scrollable, + "Element should not have a vertical scrollbar"); + } + } + +} |