8296832: Improve Swing platform support

Reviewed-by: skoivu, kizune, rhalade, prr
This commit is contained in:
Prasanta Sadhukhan 2023-01-19 04:26:22 +00:00 committed by Henry Jen
parent 2e5700a92c
commit 9e56d100df
4 changed files with 56 additions and 4 deletions

View File

@ -33,6 +33,7 @@ import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import sun.swing.SwingAccessor;
import sun.swing.SwingUtilities2;
/**
@ -220,7 +221,7 @@ public class BasicHTML {
View value = null;
View oldValue = (View)c.getClientProperty(BasicHTML.propertyKey);
Boolean htmlDisabled = (Boolean) c.getClientProperty(htmlDisable);
if (htmlDisabled != Boolean.TRUE && BasicHTML.isHTMLString(text)) {
if (!(Boolean.TRUE.equals(htmlDisabled)) && BasicHTML.isHTMLString(text)) {
value = BasicHTML.createHTMLView(c, text);
}
if (value != oldValue && oldValue != null) {
@ -376,15 +377,36 @@ public class BasicHTML {
*/
static class BasicHTMLViewFactory extends HTMLEditorKit.HTMLFactory {
public View create(Element elem) {
View view = super.create(elem);
View view = null;
try {
setAllowHTMLObject();
view = super.create(elem);
} finally {
clearAllowHTMLObject();
}
if (view instanceof ImageView) {
((ImageView)view).setLoadsSynchronously(true);
}
return view;
}
}
private static Boolean useOV = null;
@SuppressWarnings("removal")
private static void setAllowHTMLObject() {
if (useOV == null) {
useOV = java.security.AccessController.doPrivileged(
new sun.security.action.GetBooleanAction(
"swing.html.object"));
};
SwingAccessor.setAllowHTMLObject(useOV);
}
private static void clearAllowHTMLObject() {
SwingAccessor.setAllowHTMLObject(null);
}
}
/**
* The subclass of HTMLDocument that is used as the model. getForeground

View File

@ -93,6 +93,7 @@ import javax.swing.text.View;
import javax.swing.text.ViewFactory;
import javax.swing.text.html.parser.ParserDelegator;
import sun.swing.SwingAccessor;
import sun.awt.AppContext;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
@ -1402,7 +1403,11 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
(kind == HTML.Tag.TEXTAREA)) {
return new FormView(elem);
} else if (kind == HTML.Tag.OBJECT) {
return new ObjectView(elem);
if (SwingAccessor.getAllowHTMLObject()) {
return new ObjectView(elem);
} else {
return new ObjectView(elem, false);
}
} else if (kind == HTML.Tag.FRAMESET) {
if (elem.getAttributes().isDefined(HTML.Attribute.ROWS)) {
return new FrameSetView(elem, View.Y_AXIS);

View File

@ -71,6 +71,8 @@ import sun.reflect.misc.ReflectUtil;
*/
public class ObjectView extends ComponentView {
private boolean createComp = true; // default
/**
* Creates a new ObjectView object.
*
@ -80,6 +82,11 @@ public class ObjectView extends ComponentView {
super(elem);
}
ObjectView(Element elem, boolean createComp) {
super(elem);
this.createComp = createComp;
}
/**
* Create the component. The classid is used
* as a specification of the classname, which
@ -87,6 +94,9 @@ public class ObjectView extends ComponentView {
*/
@SuppressWarnings("deprecation")
protected Component createComponent() {
if (!createComp) {
return getUnloadableRepresentation();
}
AttributeSet attr = getElement().getAttributes();
String classname = (String) attr.getAttribute(HTML.Attribute.CLASSID);
try {

View File

@ -321,4 +321,19 @@ public final class SwingAccessor {
MethodHandles.lookup().ensureInitialized(c);
} catch (IllegalAccessException e) {}
}
private static ThreadLocal<Boolean> tlObj = new ThreadLocal<Boolean>();
public static Boolean getAllowHTMLObject() {
Boolean b = tlObj.get();
if (b == null) {
return Boolean.TRUE;
} else {
return b;
}
}
public static void setAllowHTMLObject(Boolean val) {
tlObj.set(val);
}
}