From b016170019b06f47c10db8bf63f45297d9beea79 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Mon, 26 Sep 2016 16:11:14 +0300 Subject: [PATCH] Revert: HTMLEditorKitProvider extracted to make initialization lazy --- .../util/ui/HTMLEditorKitProvider.java | 83 ------------------- .../util/src/com/intellij/util/ui/UIUtil.java | 46 +++++++++- 2 files changed, 45 insertions(+), 84 deletions(-) delete mode 100644 platform/util/src/com/intellij/util/ui/HTMLEditorKitProvider.java diff --git a/platform/util/src/com/intellij/util/ui/HTMLEditorKitProvider.java b/platform/util/src/com/intellij/util/ui/HTMLEditorKitProvider.java deleted file mode 100644 index dc117df42315..000000000000 --- a/platform/util/src/com/intellij/util/ui/HTMLEditorKitProvider.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.util.ui; - -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.util.registry.Registry; -import com.intellij.util.ui.accessibility.ScreenReader; -import org.jetbrains.annotations.NonNls; - -import javax.swing.*; -import javax.swing.text.html.HTMLEditorKit; -import javax.swing.text.html.StyleSheet; -import java.awt.*; - -import static com.intellij.util.ui.UIUtil.getLabelFont; -import static com.intellij.util.ui.UIUtil.isUnderDarcula; - -/** - * @author Dmitry Avdeev - */ -public class HTMLEditorKitProvider { - private static final Logger LOG = Logger.getInstance(HTMLEditorKitProvider.class); - private static final StyleSheet DEFAULT_HTML_KIT_CSS; - - static { - blockATKWrapper(); - // save the default JRE CSS and .. - HTMLEditorKit kit = new HTMLEditorKit(); - DEFAULT_HTML_KIT_CSS = kit.getStyleSheet(); - // .. erase global ref to this CSS so no one can alter it - kit.setStyleSheet(null); - } - - private static void blockATKWrapper() { - /* - * The method should be called before java.awt.Toolkit.initAssistiveTechnologies() - * which is called from Toolkit.getDefaultToolkit(). - */ - if (!(SystemInfo.isLinux && Registry.is("linux.jdk.accessibility.atkwrapper.block"))) return; - - if (ScreenReader.isEnabled(ScreenReader.ATK_WRAPPER)) { - // Replace AtkWrapper with a dummy Object. It'll be instantiated & GC'ed right away, a NOP. - System.setProperty("javax.accessibility.assistive_technologies", "java.lang.Object"); - LOG.info(ScreenReader.ATK_WRAPPER + " is blocked, see IDEA-149219"); - } - } - - public static HTMLEditorKit getHTMLEditorKit(boolean noGapsBetweenParagraphs) { - Font font = getLabelFont(); - @NonNls String family = !SystemInfo.isWindows && font != null ? font.getFamily() : "Tahoma"; - int size = font != null ? font.getSize() : JBUI.scale(11); - - String customCss = String.format("body, div, p { font-family: %s; font-size: %s; }", family, size); - if (noGapsBetweenParagraphs) { - customCss += " p { margin-top: 0; }"; - } - - final StyleSheet style = new StyleSheet(); - style.addStyleSheet(isUnderDarcula() ? (StyleSheet)UIManager.getDefaults().get("StyledEditorKit.JBDefaultStyle") : DEFAULT_HTML_KIT_CSS); - style.addRule(customCss); - - return new HTMLEditorKit() { - @Override - public StyleSheet getStyleSheet() { - return style; - } - }; - } -} diff --git a/platform/util/src/com/intellij/util/ui/UIUtil.java b/platform/util/src/com/intellij/util/ui/UIUtil.java index 7ce09776ef57..3d5aa364d598 100644 --- a/platform/util/src/com/intellij/util/ui/UIUtil.java +++ b/platform/util/src/com/intellij/util/ui/UIUtil.java @@ -30,6 +30,7 @@ import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.JBIterable; import com.intellij.util.containers.JBTreeTraverser; import com.intellij.util.containers.WeakHashMap; +import com.intellij.util.ui.accessibility.ScreenReader; import org.intellij.lang.annotations.Language; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -92,6 +93,31 @@ public class UIUtil { public static final String BORDER_LINE = "
"; + private static final StyleSheet DEFAULT_HTML_KIT_CSS; + + static { + blockATKWrapper(); + // save the default JRE CSS and .. + HTMLEditorKit kit = new HTMLEditorKit(); + DEFAULT_HTML_KIT_CSS = kit.getStyleSheet(); + // .. erase global ref to this CSS so no one can alter it + kit.setStyleSheet(null); + } + + private static void blockATKWrapper() { + /* + * The method should be called before java.awt.Toolkit.initAssistiveTechnologies() + * which is called from Toolkit.getDefaultToolkit(). + */ + if (!(SystemInfo.isLinux && Registry.is("linux.jdk.accessibility.atkwrapper.block"))) return; + + if (ScreenReader.isEnabled(ScreenReader.ATK_WRAPPER)) { + // Replace AtkWrapper with a dummy Object. It'll be instantiated & GC'ed right away, a NOP. + System.setProperty("javax.accessibility.assistive_technologies", "java.lang.Object"); + LOG.info(ScreenReader.ATK_WRAPPER + " is blocked, see IDEA-149219"); + } + } + public static int getMultiClickInterval() { Object property = Toolkit.getDefaultToolkit().getDesktopProperty("awt.multiClickInterval"); if (property instanceof Integer) { @@ -2331,7 +2357,25 @@ public class UIUtil { } public static HTMLEditorKit getHTMLEditorKit(boolean noGapsBetweenParagraphs) { - return HTMLEditorKitProvider.getHTMLEditorKit(noGapsBetweenParagraphs); + Font font = getLabelFont(); + @NonNls String family = !SystemInfo.isWindows && font != null ? font.getFamily() : "Tahoma"; + int size = font != null ? font.getSize() : JBUI.scale(11); + + String customCss = String.format("body, div, p { font-family: %s; font-size: %s; }", family, size); + if (noGapsBetweenParagraphs) { + customCss += " p { margin-top: 0; }"; + } + + final StyleSheet style = new StyleSheet(); + style.addStyleSheet(isUnderDarcula() ? (StyleSheet)UIManager.getDefaults().get("StyledEditorKit.JBDefaultStyle") : DEFAULT_HTML_KIT_CSS); + style.addRule(customCss); + + return new HTMLEditorKit() { + @Override + public StyleSheet getStyleSheet() { + return style; + } + }; } public static void removeScrollBorder(final Component c) {