Skip to content

Commit

Permalink
Merge pull request #5 from openjdk/master
Browse files Browse the repository at this point in the history
Merge from jfx
  • Loading branch information
tsayao authored Feb 14, 2020
2 parents 9397a74 + e986459 commit 37519d7
Show file tree
Hide file tree
Showing 5,817 changed files with 208,484 additions and 109,842 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion buildSrc/android.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -27,6 +27,7 @@
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.collections.ObservableListBase;
import javafx.collections.WeakListChangeListener;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
Expand All @@ -46,6 +47,8 @@ public abstract class SelectedItemsReadOnlyObservableList<E> extends ObservableL
itemsListChanged = true;
itemsListChange = c;
};
private final WeakListChangeListener weakItemsListListener =
new WeakListChangeListener(itemsListListener);

private final Supplier<Integer> modelSizeSupplier;

Expand Down Expand Up @@ -120,11 +123,11 @@ public int size() {
// Used by ListView and TableView to allow for improved handling.
public void setItemsList(ObservableList<E> itemsList) {
if (this.itemsList != null) {
this.itemsList.removeListener(itemsListListener);
this.itemsList.removeListener(weakItemsListListener);
}
this.itemsList = itemsList;
if (itemsList != null) {
itemsList.addListener(itemsListListener);
itemsList.addListener(weakItemsListListener);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,8 @@ private void rebuildUI() {
setSystemMenu(stage);
}
} else {
if (curMBSkin != null && curMBSkin.getSkinnable() != null &&
if (getSkinnable().isUseSystemMenuBar() &&
curMBSkin != null && curMBSkin.getSkinnable() != null &&
curMBSkin.getSkinnable().isUseSystemMenuBar()) {
curMBSkin.getSkinnable().setUseSystemMenuBar(false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -1928,6 +1928,7 @@ private enum DragState {
private EventHandler<MouseEvent> headerMousePressedHandler = this::handleHeaderMousePressed;
private EventHandler<MouseEvent> headerMouseReleasedHandler = this::handleHeaderMouseReleased;

private int dragTabHeaderStartIndex;
private int dragTabHeaderIndex;
private TabHeaderSkin dragTabHeader;
private TabHeaderSkin dropTabHeader;
Expand All @@ -1943,7 +1944,6 @@ private enum DragState {
// Reordering Animation
private final double ANIM_DURATION = 120;
private TabHeaderSkin dropAnimHeader;
private Tab swapTab;
private double dropHeaderSourceX;
private double dropHeaderTransitionX;
private final Animation dropHeaderAnim = new Transition() {
Expand All @@ -1958,7 +1958,6 @@ protected void interpolate(double frac) {
dropAnimHeader.setLayoutX(dropHeaderSourceX + dropHeaderTransitionX * frac);
}
};
private double dragHeaderStartX;
private double dragHeaderDestX;
private double dragHeaderSourceX;
private double dragHeaderTransitionX;
Expand All @@ -1967,6 +1966,7 @@ protected void interpolate(double frac) {
setInterpolator(Interpolator.EASE_OUT);
setCycleDuration(Duration.millis(ANIM_DURATION));
setOnFinished(event -> {
reorderTabs();
resetDrag();
});
}
Expand Down Expand Up @@ -2189,12 +2189,12 @@ private void startDrag(MouseEvent event) {
dragTabHeader = (TabHeaderSkin) event.getSource();
if (dragTabHeader != null) {
dragState = DragState.START;
swapTab = null;
xLayoutDirection = deriveTabHeaderLayoutXDirection();
dragEventPrevLoc = getHeaderRegionLocalX(event);
dragTabHeaderIndex = headersRegion.getChildren().indexOf(dragTabHeader);
dragTabHeaderStartIndex = dragTabHeaderIndex;
dragTabHeader.setViewOrder(0);
dragHeaderStartX = dragHeaderDestX = dragTabHeader.getLayoutX();
dragHeaderDestX = dragTabHeader.getLayoutX();
}
}

Expand All @@ -2210,17 +2210,19 @@ private void stopDrag() {
if (dragState == DragState.START) {
// No drag action was performed.
resetDrag();
return;
} else if (dragState == DragState.REORDER) {
// Animate tab header being dragged to its final position.
dragHeaderSourceX = dragTabHeader.getLayoutX();
dragHeaderTransitionX = dragHeaderDestX - dragHeaderSourceX;
dragHeaderAnim.playFromStart();
}
// Animate tab header being dragged to its final position.
dragHeaderSourceX = dragTabHeader.getLayoutX();
dragHeaderTransitionX = dragHeaderDestX - dragHeaderSourceX;
dragHeaderAnim.playFromStart();
}

// Reorder the tab list.
if (dragHeaderStartX != dragHeaderDestX) {
((TabObservableList<Tab>) getSkinnable().getTabs()).reorder(dragTabHeader.tab, swapTab);
swapTab = null;
private void reorderTabs() {
if (dragTabHeaderIndex != dragTabHeaderStartIndex) {
((TabObservableList<Tab>) getSkinnable().getTabs()).reorder(
getSkinnable().getTabs().get(dragTabHeaderStartIndex),
getSkinnable().getTabs().get(dragTabHeaderIndex));
}
}

Expand All @@ -2235,7 +2237,6 @@ private void resetDrag() {
// Animate tab header being dropped-on to its new position.
private void startHeaderReorderingAnim() {
dropAnimHeader = dropTabHeader;
swapTab = dropAnimHeader.tab;
dropHeaderSourceX = dropAnimHeader.getLayoutX();
dropHeaderAnim.playFromStart();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -28,6 +28,7 @@
import com.sun.javafx.scene.control.VirtualScrollBar;
import com.sun.javafx.scene.control.behavior.ListCellBehavior;
import com.sun.javafx.tk.Toolkit;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -1975,4 +1976,28 @@ public void testEventIndicesOnSelectRange() {
assertEquals("List item at index 1 should be selected", 1, (int) sm.getSelectedIndices().get(0));
assertEquals("List item at index 2 should be selected", 2, (int) sm.getSelectedIndices().get(1));
}

@Test
public void testListViewLeak() {
ObservableList<String> items = FXCollections.observableArrayList();
WeakReference<ListView<String>> listViewRef = new WeakReference<>(new ListView<>(items));
attemptGC(listViewRef, 10);
assertNull("ListView has a leak.", listViewRef.get());
}

private void attemptGC(WeakReference<ListView<String>> weakRef, int n) {
for (int i = 0; i < n; i++) {
System.gc();
System.runFinalization();

if (weakRef.get() == null) {
break;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
fail("InterruptedException occurred during Thread.sleep()");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -463,6 +463,23 @@ private void show() {
assertSame(TabPane.TabDragPolicy.FIXED, tabPane.getTabDragPolicy());
}

@Test public void tabDragPolicyReorderAndAsymmetricMouseEvent() {
tabPane.setTabDragPolicy(TabPane.TabDragPolicy.REORDER);
tabPane.getTabs().add(tab1);
tabPane.getTabs().add(tab2);
root.getChildren().add(tabPane);
show();

root.layout();

double xval = (tabPane.localToScene(tabPane.getLayoutBounds())).getMinX();
double yval = (tabPane.localToScene(tabPane.getLayoutBounds())).getMinY();

SceneHelper.processMouseEvent(scene,
MouseEventGenerator.generateMouseEvent(MouseEvent.MOUSE_RELEASED, xval+75, yval+20));
tk.firePulse();
}

@Test public void setRotateGraphicAndSeeValueIsReflectedInModel() {
tabPane.setRotateGraphic(true);
assertTrue(tabPane.rotateGraphicProperty().getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package test.javafx.scene.control.skin;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import com.sun.javafx.menu.MenuBase;
import com.sun.javafx.stage.WindowHelper;
Expand All @@ -37,6 +38,7 @@
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.stage.Stage;

import java.util.List;
Expand Down Expand Up @@ -163,6 +165,35 @@ public class MenuBarSkinTest {
}
}

@Test public void testModifyingNonSystemMenuBar() {
if (tk.getSystemMenu().isSupported()) {
// Set system menubar to true
menubar.setUseSystemMenuBar(true);

// Create a secondary menubar that is not
// a system menubar
MenuBar secondaryMenuBar = new MenuBar(
new Menu("Menu 1", null, new MenuItem("Item 1")),
new Menu("Menu 2", null, new MenuItem("Item 2")));
secondaryMenuBar.setSkin(new MenuBarSkin(secondaryMenuBar));

// Add the secondary menubar to the scene
((Group)scene.getRoot()).getChildren().add(secondaryMenuBar);

// Verify that the menubar is the system menubar
assertTrue(menubar.isUseSystemMenuBar());

// Remove a menu from the secondary menubar
// to trigger a rebuild of its UI and a call
// to the sceneProperty listener
secondaryMenuBar.getMenus().remove(1);

// Verify that this has not affected whether the
// original menubar is the system menubar
assertTrue(menubar.isUseSystemMenuBar());
}
}

public static final class MenuBarSkinMock extends MenuBarSkin {
boolean propertyChanged = false;
int propertyChangeCount = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,15 @@ public void setPeer(Object peer) {
this.peer = peer;
}

int getTableLength(int tag) {
int len = 0;
DirectoryEntry tagDE = getDirectoryEntry(tag);
if (tagDE != null) {
len = tagDE.length;
}
return len;
}

synchronized Buffer readTable(int tag) {
Buffer buffer = null;
boolean openedFile = false;
Expand Down Expand Up @@ -569,6 +578,15 @@ private void init(String name, int fIndex) throws Exception {
// font. For some fonts advanceWidthMax is much larger then "M"
// advanceWidthMax = (float)hhea.getChar(10);
numHMetrics = hhea.getChar(34) & 0xffff;
/* the hmtx table may have a trailing LSB array which we don't
* use. But it means we must not assume these two values match.
* We are only concerned here with not reading more data than
* there is in the table.
*/
int hmtxEntries = getTableLength(hmtxTag) >> 2;
if (numHMetrics > hmtxEntries) {
numHMetrics = hmtxEntries;
}
}

// maxp table is before the OS/2 table. Read it now
Expand Down
Loading

0 comments on commit 37519d7

Please sign in to comment.