Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Becker2018-02-09 04:58:32 -0500
committerMatthias Becker2018-02-12 04:06:13 -0500
commitce56a0e12ccc495fa9319cadecf18e2bf7d6a9b6 (patch)
tree8d06158f5e154a8e995a826631e9a5a4b7b17364
parent101d3f2be142e55728dd942c2504af299ba33b1f (diff)
downloadeclipse.platform.text-ce56a0e12ccc495fa9319cadecf18e2bf7d6a9b6.tar.gz
eclipse.platform.text-ce56a0e12ccc495fa9319cadecf18e2bf7d6a9b6.tar.xz
eclipse.platform.text-ce56a0e12ccc495fa9319cadecf18e2bf7d6a9b6.zip
Bug 517393: Dark theme hyper-link text is dark blue
Dark theme hyper-link text was dark blue on black background in JDT's Javadoc. The cause is that JDT's CSS contains hard-coded colors for the links. To solve this provide a mechanism in HTMLPrinter to replace symbolic color names with actual color values from the preferences. A consumer of HTMLPrinter now can you the symbolic names hyperlinkColor and activeHyperlinkColor in their stylesheets. These symbolic names are replaced with JFacePreferences.HYPERLINK_COLOR and JFacePreferences.ACTIVE_HYPERLINK_COLOR by HTMLPrinter automatically. Also fixed: If one changed the theme or color preferences the cached colors in HTMLPrinter were not updated. Change-Id: I386c0a7feff6da132b76bd3ff80c91b4fb919b67 Signed-off-by: Matthias Becker <ma.becker@sap.com>
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLPrinter.java33
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/RevisionPainter.java4
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/RevisionHoverInformationControlCreator.java4
3 files changed, 28 insertions, 13 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLPrinter.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLPrinter.java
index 0e9b4c8f0..afd745a5f 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLPrinter.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLPrinter.java
@@ -19,10 +19,9 @@ import org.eclipse.swt.SWTError;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
import org.eclipse.jface.resource.JFaceColors;
+import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.util.Util;
import org.eclipse.jface.text.DefaultInformationControl;
@@ -36,6 +35,8 @@ public class HTMLPrinter {
private static volatile RGB BG_COLOR_RGB= new RGB(255, 255, 225); // RGB value of info bg color on WindowsXP
private static volatile RGB FG_COLOR_RGB= new RGB(0, 0, 0); // RGB value of info fg color on WindowsXP
+ private static volatile RGB LINK_COLOR_RGB= new RGB(0, 0, 255); // dark blue
+ private static volatile RGB ACTIVE_LINK_COLOR_RGB= new RGB(0, 0, 128); // light blue
private static final String UNIT; // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=155993
static {
@@ -68,15 +69,13 @@ public class HTMLPrinter {
private static void cacheColors(Display display) {
BG_COLOR_RGB= JFaceColors.getInformationViewerBackgroundColor(display).getRGB();
FG_COLOR_RGB= JFaceColors.getInformationViewerForegroundColor(display).getRGB();
+ LINK_COLOR_RGB= JFaceColors.getHyperlinkText(display).getRGB();
+ ACTIVE_LINK_COLOR_RGB= JFaceColors.getActiveHyperlinkText(display).getRGB();
}
private static void installColorUpdater(final Display display) {
- display.addListener(SWT.Settings, new Listener() {
- @Override
- public void handleEvent(Event event) {
- cacheColors(display);
- }
- });
+ display.addListener(SWT.Settings, event -> cacheColors(display));
+ JFaceResources.getColorRegistry().addListener(event -> cacheColors(display));
}
private static String replace(String text, char c, String s) {
@@ -394,6 +393,14 @@ public class HTMLPrinter {
appendColor(bg, bgRGB);
styleSheet= styleSheet.replaceAll("InfoBackground", bg.toString()); //$NON-NLS-1$
+ // replace link colors with colors from preferences
+ StringBuilder linkColor= new StringBuilder();
+ appendColor(linkColor, LINK_COLOR_RGB);
+ styleSheet= styleSheet.replaceAll("hyperlinkColor", linkColor.toString()); //$NON-NLS-1$
+ StringBuilder activeLinkColor= new StringBuilder();
+ appendColor(activeLinkColor, ACTIVE_LINK_COLOR_RGB);
+ styleSheet= styleSheet.replaceAll("activeHyperlinkColor", activeLinkColor.toString()); //$NON-NLS-1$
+
buffer.append("<head><style CHARSET=\"ISO-8859-1\" TYPE=\"text/css\">"); //$NON-NLS-1$
buffer.append(styleSheet);
buffer.append("</style></head>"); //$NON-NLS-1$
@@ -414,13 +421,21 @@ public class HTMLPrinter {
return;
// workaround for https://bugs.eclipse.org/318243
- StringBuffer fg= new StringBuffer();
+ StringBuilder fg= new StringBuilder();
appendColor(fg, fgRGB);
styleSheet= styleSheet.replaceAll("InfoText", fg.toString()); //$NON-NLS-1$
StringBuilder bg= new StringBuilder();
appendColor(bg, bgRGB);
styleSheet= styleSheet.replaceAll("InfoBackground", bg.toString()); //$NON-NLS-1$
+ // replace link colors with colors from preferences
+ StringBuilder linkColor= new StringBuilder();
+ appendColor(linkColor, LINK_COLOR_RGB);
+ styleSheet= styleSheet.replaceAll("hyperlinkColor", linkColor.toString()); //$NON-NLS-1$
+ StringBuilder activeLinkColor= new StringBuilder();
+ appendColor(activeLinkColor, ACTIVE_LINK_COLOR_RGB);
+ styleSheet= styleSheet.replaceAll("activeHyperlinkColor", activeLinkColor.toString()); //$NON-NLS-1$
+
buffer.append("<head><style CHARSET=\"ISO-8859-1\" TYPE=\"text/css\">"); //$NON-NLS-1$
buffer.append(styleSheet);
buffer.append("</style></head>"); //$NON-NLS-1$
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/RevisionPainter.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/RevisionPainter.java
index 7ec2e6678..5321b8282 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/RevisionPainter.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/RevisionPainter.java
@@ -417,8 +417,8 @@ public final class RevisionPainter {
"dd { margin-top: 0; margin-bottom: 0 }\n" + //$NON-NLS-1$
"\n" + //$NON-NLS-1$
"/* Styles and colors */\n" + //$NON-NLS-1$
- "a:link { color: #0000FF }\n" + //$NON-NLS-1$
- "a:hover { color: #000080 }\n" + //$NON-NLS-1$
+ "a:link { color: hyperlinkColor }\n" + //$NON-NLS-1$
+ "a:hover { color: activeHyperlinkColor; }\n" + //$NON-NLS-1$
"a:visited { text-decoration: underline }\n" + //$NON-NLS-1$
"h4 { font-style: italic }\n" + //$NON-NLS-1$
"strong { font-weight: bold }\n" + //$NON-NLS-1$
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/RevisionHoverInformationControlCreator.java b/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/RevisionHoverInformationControlCreator.java
index 10ece5702..5f417e24e 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/RevisionHoverInformationControlCreator.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/RevisionHoverInformationControlCreator.java
@@ -53,8 +53,8 @@ class RevisionHoverInformationControlCreator extends AbstractReusableInformation
"dd { margin-top: 0; margin-bottom: 0 }\n" + //$NON-NLS-1$
"\n" + //$NON-NLS-1$
"/* Styles and colors */\n" + //$NON-NLS-1$
- "a:link { color: #0000FF }\n" + //$NON-NLS-1$
- "a:hover { color: #000080 }\n" + //$NON-NLS-1$
+ "a:link { color: hyperlinkColor }\n" + //$NON-NLS-1$
+ "a:hover { color: activeHyperlinkColor }\n" + //$NON-NLS-1$
"a:visited { text-decoration: underline }\n" + //$NON-NLS-1$
"h4 { font-style: italic }\n" + //$NON-NLS-1$
"strong { font-weight: bold }\n" + //$NON-NLS-1$

Back to the top