diff options
author | Paul Pazderski | 2020-06-02 16:04:12 +0000 |
---|---|---|
committer | Paul Pazderski | 2020-06-02 16:08:07 +0000 |
commit | 9aa26e74a1199dbed9cd439ac84668d38b6fbd99 (patch) | |
tree | a11da050ce7fc91969ddb67740d0abd0c67c9c71 | |
parent | 3acfca8cb48769e74d6a0e68a66fe398f9f5f5bd (diff) | |
download | eclipse.platform.swt-9aa26e74a1199dbed9cd439ac84668d38b6fbd99.tar.gz eclipse.platform.swt-9aa26e74a1199dbed9cd439ac84668d38b6fbd99.tar.xz eclipse.platform.swt-9aa26e74a1199dbed9cd439ac84668d38b6fbd99.zip |
Revert "Bug 507611 - CTabFolder has wrong initial size"
This reverts commit bfae5c9790e0327102cb5a33397b89aa08090059 which
introduced an ArrayIndexOutOfBoundsException in computeControlBounds
reported in bug 563822.
Change-Id: I66e9e366aa594d44db8ecbd4f37e0dee5ee8952b
Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
3 files changed, 4 insertions, 152 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java index 10d0730543..86fac25b9f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java @@ -1281,7 +1281,6 @@ public int getStyle() { public int getTabHeight(){ checkWidget(); if (fixedTabHeight != SWT.DEFAULT) return fixedTabHeight; - runUpdate(UPDATE_TAB_HEIGHT); return tabHeight - 1; // -1 for line drawn across top of tab //TODO: replace w/ computeTrim of tab area? } /** @@ -2697,7 +2696,7 @@ public void setFont(Font font) { // Redraw request alone would only redraw the cached image with old font. renderer.chevronFont = null; // renderer will pickup and adjust(!) the new font automatically updateChevronImage(true); - updateFolder(REDRAW | UPDATE_TAB_HEIGHT); + updateFolder(REDRAW); } @Override public void setForeground (Color color) { @@ -3885,30 +3884,6 @@ void updateFolder (int flags) { getDisplay().asyncExec(updateRun); } -/** - * Run pending updates if one of the given update flags is deferred for update. - * <p> - * If an update is deferred there is no guarantee if only the requested update - * is run or all pending update types. - * - * @param flags only run update if one of this update types is pending - */ -void runUpdate(int flags) { - if ((updateFlags & flags) != 0) { - // if requested update is only tab height, update only tab height - if (flags == UPDATE_TAB_HEIGHT) { - updateFlags &= ~flags; - // Changes in button state (added/removed min/max button) can influence the new - // tab height. There is no separate flag to run button updates and no need to - // introduce one because the update method is very cheap to run if nothing changed. - updateButtons(); - updateTabHeight(false); - } else { - runUpdate(); - } - } -} - void runUpdate() { if (updateFlags == 0) return; int flags = updateFlags; diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderRenderer.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderRenderer.java index 8a0d9cb10a..c9b7aa7e14 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderRenderer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderRenderer.java @@ -402,10 +402,9 @@ public class CTabFolderRenderer { int borderRight = borderLeft; int borderTop = parent.onBottom ? borderLeft : 0; int borderBottom = parent.onBottom ? 0 : borderLeft; + int tabHeight = parent.tabHeight; switch (part) { case PART_BODY: - parent.runUpdate(CTabFolder.UPDATE_TAB_HEIGHT); - int tabHeight = parent.tabHeight; int style = parent.getStyle(); int highlight_header = (style & SWT.FLAT) != 0 ? 1 : 3; int highlight_margin = (style & SWT.FLAT) != 0 ? 0 : 2; @@ -789,7 +788,6 @@ public class CTabFolderRenderer { void drawBody(GC gc, Rectangle bounds, int state) { Point size = new Point(bounds.width, bounds.height); int selectedIndex = parent.selectedIndex; - parent.runUpdate(CTabFolder.UPDATE_TAB_HEIGHT); int tabHeight = parent.tabHeight; int borderLeft = parent.borderVisible ? 1 : 0; @@ -1795,7 +1793,6 @@ public class CTabFolderRenderer { void updateCurves () { //Temp fix for Bug 384743 if (this.getClass().getName().equals("org.eclipse.e4.ui.workbench.renderers.swt.CTabRendering")) return; - parent.runUpdate(CTabFolder.UPDATE_TAB_HEIGHT); int tabHeight = parent.tabHeight; if (tabHeight == lastTabHeight) return; lastTabHeight = tabHeight; diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java index 6ea3fbc728..8f0743c425 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java @@ -25,8 +25,6 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiConsumer; import org.eclipse.swt.SWT; @@ -52,6 +50,7 @@ import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; import org.eclipse.swt.widgets.Widget; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; /** @@ -199,9 +198,7 @@ public void test_setHighlightEnabled () { assertTrue(ctabFolder.getHighlightEnabled()); } -/** - * Test for bug 507611. - */ +@Ignore("Currently failing due to Bug 507611. E.g: Height is 50 instead of being at least 59") @Test public void test_checkSize() { shell.setLayout(new GridLayout(1, false)); @@ -424,123 +421,6 @@ public void test_iconWrappedOnNextLine() { } } -/** - * As default the CTabFolder tab row adjust its height automatically as required for the shown content. - * This test checks if height changes for different operations including: font size change, showing tab image, - * min/max icon and chevron. - */ -@Test -public void test_tabHeightPreferedResize() { - createTabFolder(null); - - AtomicInteger oldTabHeight = new AtomicInteger(); - AtomicReference<Rectangle> oldClientArea = new AtomicReference<>(); - // function to check if tab height changed since last check - // direction <= -1 -> expect height has shrunk - // direction = 0 -> expect height did not changed - // direction >= 1 -> expect height has grown - // msg = optional message to be appended on assertion message - BiConsumer<Integer, String> assertTabHeightChange = (direction, msg) -> { - int newTabHeight = ctabFolder.getTabHeight(); - Rectangle newClientArea = ctabFolder.getClientArea(); - String assertMsgTemplate = "Tab %s should %s%s. %d %s %d"; - if (msg == null) { - msg = ""; - } - if (!msg.isEmpty() && !msg.startsWith(" ")) { - msg = " " + msg; - } - if (direction > 0) { - assertTrue(String.format(assertMsgTemplate, "height", "grow", msg, newTabHeight, ">", oldTabHeight.get()), newTabHeight > oldTabHeight.get()); - assertTrue(String.format(assertMsgTemplate, "client area offset", "grow", msg, newClientArea.y, ">", oldClientArea.get().y), newClientArea.y > oldClientArea.get().y); - } else if (direction < 0) { - assertTrue(String.format(assertMsgTemplate, "height", "shrink", msg, newTabHeight, "<", oldTabHeight.get()), newTabHeight < oldTabHeight.get()); - assertTrue(String.format(assertMsgTemplate, "client area offset", "shrink", msg, newClientArea.y, "<", oldClientArea.get().y), newClientArea.y < oldClientArea.get().y); - } else { - assertTrue(String.format(assertMsgTemplate, "height", "not change", msg, newTabHeight, "==", oldTabHeight.get()), newTabHeight == oldTabHeight.get()); - assertTrue(String.format(assertMsgTemplate, "client area offset", "not change", msg, newClientArea.y, "==", oldClientArea.get().y), newClientArea.y == oldClientArea.get().y); - } - oldTabHeight.set(newTabHeight); - oldClientArea.set(newClientArea); - }; - Runnable rememberTabHeight = () -> { - oldTabHeight.set(ctabFolder.getTabHeight()); - oldClientArea.set(ctabFolder.getClientArea()); - }; - - Font initalFont = ctabFolder.getFont(); - FontData[] existingFontData = initalFont.getFontData(); - existingFontData[0].setName(SwtTestUtil.testFontName); - existingFontData[0].setHeight(3); - Font smallFont = new Font(ctabFolder.getDisplay(), existingFontData); - existingFontData[0].setHeight(20); - Font largeFont = new Font(ctabFolder.getDisplay(), existingFontData); - existingFontData[0].setHeight(55); - Font hugeFont = new Font(ctabFolder.getDisplay(), existingFontData); - try { - SwtTestUtil.openShell(shell); - rememberTabHeight.run(); - - // Test tab height changes due to font size change - ctabFolder.setFont(smallFont); - assertTabHeightChange.accept(-1, "with smaller font"); - - ctabFolder.setFont(largeFont); - assertTabHeightChange.accept(+1, "with larger font"); - - ctabFolder.setFont(initalFont); - assertTabHeightChange.accept(-1, "with smaller font"); - - // Test tab height can change from showing min/max icon - ctabFolder.setFont(smallFont); - rememberTabHeight.run(); - ctabFolder.setMinimizeVisible(true); - assertTabHeightChange.accept(+1, "with minimize icon"); - - ctabFolder.setMaximizeVisible(true); - assertTabHeightChange.accept(0, ""); - - ctabFolder.setMinimizeVisible(false); - ctabFolder.setMaximizeVisible(false); - assertTabHeightChange.accept(-1, "without icons"); - - // Test tab height change with tab icon - Image systemIcon = ctabFolder.getDisplay().getSystemImage(SWT.ICON_INFORMATION); - ctabFolder.setSelection(0); - ctabFolder.getItem(0).setImage(systemIcon); - assertTabHeightChange.accept(+1, "with tab icon"); - - ctabFolder.getItem(0).setImage(null); - ctabFolder.getItem(1).setImage(systemIcon); - ctabFolder.setUnselectedImageVisible(true); - assertTabHeightChange.accept(0, ""); - - ctabFolder.getItem(0).setFont(hugeFont); - assertTabHeightChange.accept(+1, "with font larger than icon"); - - // Test tab height change with chevron - createTabFolder(null, 10); - ctabFolder.setFont(smallFont); - shell.layout(true, true); - processEvents(); - rememberTabHeight.run(); - showChevron(); - assertTabHeightChange.accept(+1, "with chevron"); - - createTabFolder(null, 10); - ctabFolder.setFont(largeFont); - shell.layout(true, true); - processEvents(); - rememberTabHeight.run(); - showChevron(); - assertTabHeightChange.accept(0, "with chevron"); - } finally { - smallFont.dispose(); - largeFont.dispose(); - hugeFont.dispose(); - } -} - private void processEvents() { Display display = shell.getDisplay(); |