Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrushforth committed Feb 7, 2020
2 parents e21fd1f + a74137a commit fde42da
Show file tree
Hide file tree
Showing 25 changed files with 1,010 additions and 97 deletions.
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
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 @@ -2215,12 +2215,14 @@ private void stopDrag() {
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
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) 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 @@ -131,7 +131,7 @@ static CssStyleHelper createStyleHelper(final Node node) {
}
node.styleHelper.cacheContainer.forceSlowpath = true;
node.styleHelper.triggerStates.addAll(triggerStates[0]);
node.styleHelper.firstStyleableAncestor = findFirstStyleableAncestor(node);

updateParentTriggerStates(node, depth, triggerStates);
return node.styleHelper;

Expand Down Expand Up @@ -299,6 +299,9 @@ private static boolean canReuseStyleHelper(final Node node, final StyleMap style
return false;
}

//update ancestor since this node may have changed positions in the scene graph (JDK-8237469)
node.styleHelper.firstStyleableAncestor = findFirstStyleableAncestor(node);

// If the style maps are the same instance, we can re-use the current styleHelper if the cacheContainer is null.
// Under this condition, there are no styles for this node _and_ no styles inherit.
if (node.styleHelper.cacheContainer == null) {
Expand Down
Loading

0 comments on commit fde42da

Please sign in to comment.