Skip to content

Commit

Permalink
JBR-7860 revert OpenJDK changes causing the issue with links in Quick…
Browse files Browse the repository at this point in the history
… Documentation popup

Revert "8326734: text-decoration applied to <span> lost when mixed with <u> or <s>"

This reverts commit 256f0c9.

Revert "8335967: "text-decoration: none" does not work with "A" HTML tags"

This reverts commit 734415d.
  • Loading branch information
vprovodin committed Nov 23, 2024
1 parent 4834a41 commit b0e5090
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 695 deletions.
18 changes: 1 addition & 17 deletions src/java.desktop/share/classes/javax/swing/text/html/CSS.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2023, 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 @@ -851,22 +851,6 @@ Object getInternalCSSValue(CSS.Attribute key, String value) {
return r != null ? r : conv.parseCssValue(key.getDefaultValue());
}

static Object mergeTextDecoration(String value) {
if (value.startsWith("none")) {
return null;
}

boolean underline = value.contains("underline");
boolean strikeThrough = value.contains("line-through");
if (!underline && !strikeThrough) {
return null;
}
String newValue = underline && strikeThrough
? "underline,line-through"
: (underline ? "underline" : "line-through");
return new StringValue().parseCssValue(newValue);
}

/**
* Maps from a StyleConstants to a CSS Attribute.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2506,7 +2506,7 @@ public HTMLReader(int offset, int popDepth, int pushDepth,
tagMap.put(HTML.Tag.SCRIPT, ha);
tagMap.put(HTML.Tag.SELECT, fa);
tagMap.put(HTML.Tag.SMALL, ca);
tagMap.put(HTML.Tag.SPAN, new ConvertSpanAction());
tagMap.put(HTML.Tag.SPAN, ca);
tagMap.put(HTML.Tag.STRIKE, conv);
tagMap.put(HTML.Tag.S, conv);
tagMap.put(HTML.Tag.STRONG, ca);
Expand Down Expand Up @@ -3430,53 +3430,47 @@ public void start(HTML.Tag t, MutableAttributeSet attr) {
if (styleAttributes != null) {
charAttr.addAttributes(styleAttributes);
}

convertAttributes(t, attr);
}

public void end(HTML.Tag t) {
popCharacterStyle();
}

/**
* Converts HTML tags to CSS attributes.
* @param t the current HTML tag
* @param attr the attributes of the HTML tag
*/
void convertAttributes(HTML.Tag t, MutableAttributeSet attr) {
}
}

final class ConvertSpanAction extends CharacterAction {
@Override
void convertAttributes(HTML.Tag t, MutableAttributeSet attr) {
Object newDecoration = attr.getAttribute(CSS.Attribute.TEXT_DECORATION);
Object previousDecoration =
charAttrStack.peek()
.getAttribute(CSS.Attribute.TEXT_DECORATION);

if (newDecoration != null
&& !"none".equals(newDecoration.toString())
&& previousDecoration != null
&& !"none".equals(previousDecoration.toString())) {
StyleSheet sheet = getStyleSheet();
sheet.addCSSAttribute(charAttr,
CSS.Attribute.TEXT_DECORATION,
CSS.mergeTextDecoration(newDecoration + ","
+ previousDecoration)
.toString());
}
}
}

/**
* Provides conversion of HTML tag/attribute
* mappings that have a corresponding StyleConstants
* and CSS mapping. The conversion is to CSS attributes.
*/
final class ConvertAction extends CharacterAction {
@Override
void convertAttributes(HTML.Tag t, MutableAttributeSet attr) {
class ConvertAction extends TagAction {

public void start(HTML.Tag t, MutableAttributeSet attr) {
pushCharacterStyle();
if (!foundInsertTag) {
// Note that the third argument should really be based off
// inParagraph and impliedP. If we're wrong (that is
// insertTagDepthDelta shouldn't be changed), we'll end up
// removing an extra EndSpec, which won't matter anyway.
boolean insert = canInsertTag(t, attr, false);
if (foundInsertTag) {
if (!inParagraph) {
inParagraph = impliedP = true;
}
}
if (!insert) {
return;
}
}
if (attr.isDefined(IMPLIED)) {
attr.removeAttribute(IMPLIED);
}
if (styleAttributes != null) {
charAttr.addAttributes(styleAttributes);
}
// We also need to add attr, otherwise we lose custom
// attributes, including class/id for style lookups, and
// further confuse style lookup (doesn't have tag).
charAttr.addAttribute(t, attr.copyAttributes());
StyleSheet sheet = getStyleSheet();
if (t == HTML.Tag.B) {
sheet.addCSSAttribute(charAttr, CSS.Attribute.FONT_WEIGHT, "bold");
Expand Down Expand Up @@ -3517,6 +3511,11 @@ void convertAttributes(HTML.Tag t, MutableAttributeSet attr) {
}
}
}

public void end(HTML.Tag t) {
popCharacterStyle();
}

}

class AnchorAction extends CharacterAction {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2018, 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 All @@ -24,16 +24,9 @@
*/
package javax.swing.text.html;

import javax.swing.text.*;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.stream.Collectors;

import javax.swing.text.AttributeSet;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import java.util.*;

/**
* An implementation of <code>AttributeSet</code> that can multiplex
Expand Down Expand Up @@ -203,24 +196,15 @@ public AttributeSet copyAttributes() {
* @see AttributeSet#getAttribute
*/
public Object getAttribute(Object key) {
final AttributeSet[] as = getAttributes();
final int n = as.length;
if (key != CSS.Attribute.TEXT_DECORATION) {
for (int i = 0; i < n; i++) {
Object o = as[i].getAttribute(key);
if (o != null) {
return o;
}
AttributeSet[] as = getAttributes();
int n = as.length;
for (int i = 0; i < n; i++) {
Object o = as[i].getAttribute(key);
if (o != null) {
return o;
}
return null;
}

String values = Arrays.stream(as)
.map(a -> a.getAttribute(key))
.filter(Objects::nonNull)
.map(Object::toString)
.collect(Collectors.joining(","));
return CSS.mergeTextDecoration(values);
return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, 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 All @@ -24,53 +24,17 @@
*/
package javax.swing.text.html;

import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Serializable;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.EmptyStackException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.Vector;

import sun.swing.SwingUtilities2;
import java.util.*;
import java.awt.*;
import java.io.*;
import java.net.*;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.UIManager;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.border.*;
import javax.swing.event.ChangeListener;
import javax.swing.text.AttributeSet;
import javax.swing.text.Document;
import javax.swing.text.Element;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.StyledDocument;
import javax.swing.text.View;

import sun.swing.SwingUtilities2;
import javax.swing.text.*;

/**
* Support for defining the visual characteristics of
Expand Down Expand Up @@ -2856,31 +2820,10 @@ public Object getAttribute(Object key) {
return doGetAttribute(key);
}

/**
* Merges the current value of the 'text-decoration' property
* with the value from parent.
*/
private Object getTextDecoration(Object value) {
AttributeSet parent = getResolveParent();
if (parent == null) {
return value;
}

Object parentValue = parent.getAttribute(CSS.Attribute.TEXT_DECORATION);
return parentValue == null
? value
: CSS.mergeTextDecoration(value + "," + parentValue);
}

Object doGetAttribute(Object key) {
Object retValue = super.getAttribute(key);
if (retValue != null) {
if (key != CSS.Attribute.TEXT_DECORATION) {
return retValue;
} else {
// Merge current value with parent
return getTextDecoration(retValue);
}
return retValue;
}

if (key == CSS.Attribute.FONT_SIZE) {
Expand Down
Loading

0 comments on commit b0e5090

Please sign in to comment.