Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrushforth committed Aug 30, 2019
2 parents a0b4b14 + a1aa38a commit 592d745
Show file tree
Hide file tree
Showing 10 changed files with 330 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .hgtags
Original file line number Diff line number Diff line change
Expand Up @@ -539,3 +539,5 @@ c8cde739aa8e3745e5c7686661d196f9d980a8c7 13+7
c91a28ed4845c265cd3d3340755e018da5e10698 13+10
030420e44e748f392b07f6f9c5ee0ae4b582fe56 13+11
e21afe5aabed9f81fdcc7fe061536e2c13d19456 13+12
dde636c6219c01c7d640f04acd92a344d6f9f421 13+13
6425e1f958fcad3bc17299880c167306273207dd 13+14
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import javafx.scene.text.HitInfo;

import java.text.Bidi;
import java.util.List;
import java.util.Locale;
import java.util.function.Consumer;

Expand Down Expand Up @@ -693,6 +694,10 @@ public static void addMnemonics(ContextMenu popup, Scene scene) {
}

public static void addMnemonics(ContextMenu popup, Scene scene, boolean initialState) {
addMnemonics(popup, scene, initialState, null);
}

public static void addMnemonics(ContextMenu popup, Scene scene, boolean initialState, List<Mnemonic> into) {

if (!com.sun.javafx.PlatformUtil.isMac()) {

Expand All @@ -713,6 +718,9 @@ public static void addMnemonics(ContextMenu popup, Scene scene, boolean initialS
Mnemonic myMnemonic = new Mnemonic(cmContent.getLabelAt(i), mnemonicKeyCombo);
scene.addMnemonic(myMnemonic);
NodeHelper.setShowMnemonics(cmContent.getLabelAt(i), initialState);
if (into != null) {
into.add(myMnemonic);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,21 @@
import javafx.collections.ListChangeListener;
import javafx.event.ActionEvent;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuButton;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Skin;
import javafx.scene.control.SkinBase;
import javafx.scene.input.Mnemonic;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import com.sun.javafx.scene.control.behavior.MenuButtonBehaviorBase;

import java.util.ArrayList;
import java.util.List;

/**
* Base class for MenuButtonSkin and SplitMenuButtonSkin. It consists of the
* label, the arrowButton with its arrow shape, and the popup.
Expand Down Expand Up @@ -168,6 +173,7 @@ public MenuButtonSkinBase(final C control) {
label.setMnemonicParsing(getSkinnable().isMnemonicParsing());
getSkinnable().requestLayout();
});
List<Mnemonic> mnemonics = new ArrayList<>();
registerChangeListener(popup.showingProperty(), e -> {
if (!popup.isShowing() && getSkinnable().isShowing()) {
// Popup was dismissed. Maybe user clicked outside or typed ESCAPE.
Expand All @@ -176,7 +182,8 @@ public MenuButtonSkinBase(final C control) {
}

if (popup.isShowing()) {
Utils.addMnemonics(popup, getSkinnable().getScene(), NodeHelper.isShowMnemonics(getSkinnable()));
boolean showMnemonics = NodeHelper.isShowMnemonics(getSkinnable());
Utils.addMnemonics(popup, getSkinnable().getScene(), showMnemonics, mnemonics);
} else {
// we wrap this in a runLater so that mnemonics are not removed
// before all key events are fired (because KEY_PRESSED might have
Expand All @@ -185,7 +192,10 @@ public MenuButtonSkinBase(final C control) {
// through the mnemonics code (especially in case they should be
// consumed to prevent them being used elsewhere).
// See JBS-8090026 for more detail.
Platform.runLater(() -> Utils.removeMnemonics(popup, getSkinnable().getScene()));
Scene scene = getSkinnable().getScene();
List<Mnemonic> mnemonicsToRemove = new ArrayList<>(mnemonics);
mnemonics.clear();
Platform.runLater(() -> mnemonicsToRemove.forEach(scene::removeMnemonic));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,12 +895,7 @@ protected void setPlatformEnabled(boolean enabled) {
if (platformWindow != null) {
platformWindow.setEnabled(enabled);
}
if (enabled) {
// Check if window is really enabled - to handle nested case
if (platformWindow != null && platformWindow.isEnabled()) {
requestToFront();
}
} else {
if (!enabled) {
removeActiveWindow(this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,17 @@ public void updateBuffer(Callback<PixelBuffer<T>, Rectangle2D> callback) {
Toolkit.getToolkit().checkFxUserThread();
Objects.requireNonNull(callback, "callback must not be null.");
Rectangle2D rect2D = callback.call(this);
Rectangle rect = null;
if (rect2D != null) {
int x1 = (int) Math.floor(rect2D.getMinX());
int y1 = (int) Math.floor(rect2D.getMinY());
int x2 = (int) Math.ceil(rect2D.getMaxX());
int y2 = (int) Math.ceil(rect2D.getMaxY());
rect = new Rectangle(x1, y1, x2 - x1, y2 - y1);
if (rect2D.getWidth() > 0 && rect2D.getHeight() > 0) {
int x1 = (int) Math.floor(rect2D.getMinX());
int y1 = (int) Math.floor(rect2D.getMinY());
int x2 = (int) Math.ceil(rect2D.getMaxX());
int y2 = (int) Math.ceil(rect2D.getMaxY());
bufferDirty(new Rectangle(x1, y1, x2 - x1, y2 - y1));
}
} else {
bufferDirty(null);
}
bufferDirty(rect);
}

private void bufferDirty(Rectangle rect) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ public void testUpdatePixelBufferPartialBufferUpdate() {
pixelBuffer.updateBuffer(callback);
}

@Test
public void testUpdatePixelBufferEmptyBufferUpdate() {
// This test verifies that an empty dirty region does not cause any exception
PixelBuffer<ByteBuffer> pixelBuffer = new PixelBuffer<>(WIDTH, HEIGHT, BYTE_BUFFER, BYTE_BGRA_PRE_PF);
Callback<PixelBuffer<ByteBuffer>, Rectangle2D> callback = pixBuf -> {
// Assuming no pixels were modified.
return Rectangle2D.EMPTY;
};
pixelBuffer.updateBuffer(callback);
}

@Test
public void testUpdatePixelBufferCallbackNull() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "EditorClientJava.h"
#include "FrameLoaderClientJava.h"
#include "InspectorClientJava.h"
#include "PageStorageSessionProvider.h"
#include "PlatformStrategiesJava.h"
#include "ProgressTrackerClientJava.h"
#include "VisitedLinkStoreJava.h"
Expand All @@ -59,6 +60,7 @@
#include <WebCore/Chrome.h>
#include <WebCore/ContextMenu.h>
#include <WebCore/ContextMenuController.h>
#include <WebCore/CookieJar.h>
#include <WebCore/DeprecatedGlobalSettings.h>
#include <WebCore/Document.h>
#include <WebCore/DragController.h>
Expand Down Expand Up @@ -875,7 +877,8 @@ JNIEXPORT jlong JNICALL Java_com_sun_webkit_WebPage_twkCreatePage
//utaTODO: history agent implementation

auto pc = pageConfigurationWithEmptyClients();

auto pageStorageSessionProvider = PageStorageSessionProvider::create();
pc.cookieJar = CookieJar::create(pageStorageSessionProvider.copyRef());
pc.chromeClient = new ChromeClientJava(jlself);
pc.contextMenuClient = new ContextMenuClientJava(jlself);
pc.editorClient = makeUniqueRef<EditorClientJava>(jlself);
Expand All @@ -889,10 +892,10 @@ JNIEXPORT jlong JNICALL Java_com_sun_webkit_WebPage_twkCreatePage
pc.progressTrackerClient = new ProgressTrackerClientJava(jlself);

pc.backForwardClient = BackForwardList::create();

auto page = std::make_unique<Page>(WTFMove(pc));
// Associate PageSupplementJava instance which has WebPage java object.
page->provideSupplement(PageSupplementJava::supplementName(), std::make_unique<PageSupplementJava>(self));
pageStorageSessionProvider->setPage(*page);
#if ENABLE(GEOLOCATION)
WebCore::provideGeolocationTo(page.get(), *new GeolocationClientMock());
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ public void call(long createdTime, long interval, int index) {
}
}

@Test public void testCookieEnabled() {
final WebEngine webEngine = createWebEngine();
submit(() -> {
final JSObject window = (JSObject) webEngine.executeScript("window");
assertNotNull(window);
webEngine.executeScript("var cookieEnabled = navigator.cookieEnabled");
assertTrue((Boolean)window.getMember("cookieEnabled"));
});
}

// This test case will be removed once we implement Websql feature.
@Test public void testWebSQLUndefined() {
final WebEngine webEngine = createWebEngine();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright (c) 2019, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package test.javafx.scene.control;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import test.util.Util;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class MenuButtonSkinBaseNPETest {
static CountDownLatch startupLatch;
static Menu menu;
static MenuBar menuBar;

public static void main(String[] args) throws Exception {
initFX();
try {
var test = new MenuButtonSkinBaseNPETest();
test.testMenuButtonNPE();
} catch (Throwable e) {
e.printStackTrace();
} finally {
tearDown();
}
}

@Test
public void testMenuButtonNPE() throws Exception {
PrintStream defaultErrorStream = System.err;
ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setErr(new PrintStream(out, true));
Thread.sleep(1000);
Util.runAndWait(() -> {
menu.hide();
menuBar.getMenus().clear();
});
Thread.sleep(100);
System.setErr(defaultErrorStream);
Assert.assertEquals("No error should be thrown", "", out.toString());
}

public static class TestApp extends Application {

@Override
public void start(Stage primaryStage) throws Exception {
menu = new Menu("Menu", null, new MenuItem("Press '_a'"));
menuBar = new MenuBar(menu);
Scene scene = new Scene(menuBar);
primaryStage.addEventHandler(WindowEvent.WINDOW_SHOWN, event -> startupLatch.countDown());
primaryStage.setScene(scene);
primaryStage.show();
menu.show();
}
}

@BeforeClass
public static void initFX() throws Exception {
startupLatch = new CountDownLatch(1);
new Thread(() -> Application.launch(TestApp.class, (String[])null)).start();
Assert.assertTrue("Timeout waiting for FX runtime to start",
startupLatch.await(15, TimeUnit.SECONDS));
}

@AfterClass
public static void tearDown() {
Platform.exit();
}
}
Loading

0 comments on commit 592d745

Please sign in to comment.