-
Notifications
You must be signed in to change notification settings - Fork 542
8368478: RichTextArea: add IME support #1938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
18d2f31
5427e91
9dc3fe3
8f22c2c
af26ad5
89c6fff
313646f
3bf4937
d269071
e6a7c7f
3bb8d85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * Copyright (c) 2025, 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 com.sun.jfx.incubator.scene.control.richtext; | ||
|
|
||
| import com.sun.javafx.util.Utils; | ||
| import com.sun.jfx.incubator.scene.control.richtext.util.ListenerHelper; | ||
| import jfx.incubator.scene.control.richtext.RichTextArea; | ||
| import jfx.incubator.scene.control.richtext.TextPos; | ||
| import jfx.incubator.scene.control.richtext.skin.RichTextAreaSkin; | ||
|
|
||
| /** | ||
| * Manages RichTextArea Accessor. | ||
| */ | ||
| public class RichTextAreaHelper { | ||
|
|
||
| public interface Accessor { | ||
| public boolean getText(RichTextArea t, TextPos start, TextPos end, StringBuilder sb, int limit); | ||
| } | ||
|
|
||
| static { | ||
| Utils.forceInit(RichTextArea.class); | ||
| } | ||
|
|
||
| private static Accessor accessor; | ||
|
|
||
| public static void setAccessor(Accessor a) { | ||
| if (accessor != null) { | ||
| // this code might break when RTA is created outside of the fx application thread | ||
| // I am not sure what this check does really | ||
| throw new IllegalStateException(); | ||
| } | ||
| accessor = a; | ||
| } | ||
|
|
||
| public static boolean getText(RichTextArea t, TextPos start, TextPos end, StringBuilder sb, int limit) { | ||
| return accessor.getText(t, start, end, sb, limit); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved. | ||
| * Copyright (c) 2022, 2025, 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 | ||
|
|
@@ -212,6 +212,38 @@ public PathElement[] getCaretShape(Region target, int charIndex, boolean leading | |
| return RichUtils.translatePath(target, content, p, dx, dy); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the {@code PathElement} array for the underline shape, | ||
| * translated to the {@code target} frame of reference. | ||
| * | ||
| * @param target the Region that provides the target frame of reference | ||
| * @param start the start offset | ||
| * @param end the end offset | ||
| * @return the array of path elements translated to the target coordinates | ||
| */ | ||
| public PathElement[] getUnderlineShape(Region target, int start, int end) { | ||
| PathElement[] p; | ||
| double dx; | ||
| double dy; | ||
| if (content instanceof TextFlow f) { | ||
| dx = f.snappedLeftInset(); // TODO RTL? | ||
| dy = f.snappedTopInset(); | ||
|
|
||
| p = f.getUnderlineShape(start, end); | ||
| } else { | ||
| dx = 0.0; | ||
| dy = 0.0; | ||
| double w = getWidth(); | ||
| double h = getHeight(); | ||
|
|
||
| p = new PathElement[] { | ||
| new MoveTo(0.0, h), | ||
| new LineTo(w, h) | ||
| }; | ||
| } | ||
| return RichUtils.translatePath(target, content, p, dx, dy); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the {@code PathElement} array for the range shape, | ||
| * translated to the {@code target} frame of reference. | ||
|
|
@@ -229,7 +261,7 @@ public PathElement[] getRangeShape(Region target, int start, int end) { | |
| dx = f.snappedLeftInset(); // TODO RTL? | ||
| dy = f.snappedTopInset(); | ||
|
|
||
| p = f.rangeShape(start, end); | ||
| p = f.rangeShape(start, end); // TODO new api, no null | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this "TODO" really related to IME? If not, I recommend removing it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this code predates JDK-8357594
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for filing the RFE. Since you aren't otherwise modifying this method in this PR, adding a random TODO like this seems like an unrelated change. Now if you meant to also add this comment to line 232 (the call to So I recommend either adding a similar comment on line 232, or removing the unrelated TODOs. |
||
|
|
||
| if ((p == null) || (p.length == 0)) { | ||
| p = new PathElement[] { | ||
|
|
@@ -365,7 +397,7 @@ public Integer lineEnd(int line) { | |
| private RangeInfo getTextRange() { | ||
| if (content instanceof TextFlow f) { | ||
| int len = getTextLength(); | ||
| PathElement[] pe = f.rangeShape(0, len); | ||
| PathElement[] pe = f.rangeShape(0, len); // TODO new api | ||
| if (pe.length > 0) { | ||
| double sp = f.getLineSpacing(); | ||
| return RangeInfo.of(pe, sp); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.