Skip to content

Commit 286d1b5

Browse files
arun-josephkevinrushforth
authored andcommittedNov 6, 2019
8230492: font-family not set in HTMLEditor if font name has a number in it
Reviewed-by: kcr, shadzic
1 parent f74f3af commit 286d1b5

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed
 

‎modules/javafx.web/src/main/java/javafx/scene/web/HTMLEditorSkin.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ private void populateToolbars() {
689689
});
690690

691691
fontFamilyComboBox.valueProperty().addListener((observable, oldValue, newValue) -> {
692-
executeCommand(FONT_FAMILY.getCommand(), ("".equals(newValue)) ? "''" : newValue);
692+
executeCommand(FONT_FAMILY.getCommand(), "'" + newValue + "'");
693693
});
694694

695695
fontSizeComboBox = new ComboBox<String>();
@@ -1139,7 +1139,7 @@ private void applyTextFormatting() {
11391139
String font = fontFamilyComboBox.getValue().toString();
11401140

11411141
executeCommand(FORMAT.getCommand(), format);
1142-
executeCommand(FONT_FAMILY.getCommand(), font);
1142+
executeCommand(FONT_FAMILY.getCommand(), "'" + font + "'");
11431143
}
11441144
}
11451145

‎tests/system/src/test/java/test/javafx/scene/web/HTMLEditorTest.java

+60
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@
3131
import javafx.application.Application;
3232
import javafx.application.Platform;
3333
import javafx.event.Event;
34+
import javafx.scene.control.ComboBox;
3435
import javafx.scene.input.KeyCode;
3536
import javafx.scene.input.KeyEvent;
37+
import javafx.scene.Node;
3638
import javafx.scene.Scene;
39+
import javafx.scene.text.Font;
3740
import javafx.scene.web.HTMLEditor;
3841
import javafx.scene.web.WebView;
3942
import javafx.stage.Stage;
@@ -84,6 +87,12 @@ public static void setupOnce() {
8487
new Thread(() -> Application.launch(HTMLEditorTestApp.class,
8588
(String[]) null)).start();
8689

90+
// Used by selectFontFamilysWithSpace() for JDK-8230492
91+
Font.loadFont(
92+
HTMLEditorTest.class.getResource("WebKit_Layout_Tests_2.ttf").toExternalForm(),
93+
10
94+
);
95+
8796
assertTrue("Timeout waiting for FX runtime to start", Util.await(launchLatch));
8897
}
8998

@@ -294,4 +303,55 @@ public void checkStyleProperty() throws Exception {
294303
assertNotNull("result must have a valid reference ", result.get());
295304
assertEquals("document.body.style.fontWeight must be bold ", "bold", result.get());
296305
}
306+
307+
/**
308+
* @test
309+
* @bug 8230492
310+
* Summary Check font-family change on font name with numbers
311+
*/
312+
@Test
313+
public void selectFontFamilyWithSpace() {
314+
final CountDownLatch editorStateLatch = new CountDownLatch(1);
315+
final AtomicReference<String> result = new AtomicReference<>();
316+
317+
Util.runAndWait(() -> {
318+
webView.getEngine().getLoadWorker().stateProperty().
319+
addListener((observable, oldValue, newValue) -> {
320+
if (newValue == SUCCEEDED) {
321+
htmlEditor.requestFocus();
322+
}
323+
});
324+
325+
htmlEditor.setHtmlText("<body>Sample Text</body>");
326+
327+
webView.focusedProperty().
328+
addListener((observable, oldValue, newValue) -> {
329+
if (newValue) {
330+
ComboBox<String> fontFamilyComboBox = null;
331+
int i = 0;
332+
for (Node comboBox : htmlEditor.lookupAll(".font-menu-button")) {
333+
// 0 - Format, 1 - Font Family, 2 - Font Size
334+
if (i == 1) {
335+
assertTrue("fontFamilyComboBox must be ComboBox",
336+
comboBox instanceof ComboBox);
337+
fontFamilyComboBox = (ComboBox<String>) comboBox;
338+
assertNotNull("fontFamilyComboBox must not be null",
339+
fontFamilyComboBox);
340+
}
341+
i++;
342+
}
343+
webView.getEngine().
344+
executeScript("document.execCommand('selectAll', false, 'true');");
345+
fontFamilyComboBox.getSelectionModel().select("WebKit Layout Tests 2");
346+
result.set(htmlEditor.getHtmlText());
347+
editorStateLatch.countDown();
348+
}
349+
});
350+
});
351+
352+
assertTrue("Timeout when waiting for focus change ", Util.await(editorStateLatch));
353+
assertNotNull("result must have a valid reference ", result.get());
354+
assertTrue("font-family must be 'WebKit Layout Test 2' ", result.get().
355+
contains("font-family: &quot;WebKit Layout Tests 2&quot;"));
356+
}
297357
}
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.