From 155624f4f55e989e35261f8bdf3178a8d54fb017 Mon Sep 17 00:00:00 2001 From: Aleksandr Izmailov Date: Tue, 15 Oct 2024 19:44:37 +0200 Subject: [PATCH] LLM-11514: AI Promo Window (cherry picked from commit 697963592532aba7e6bd23d2fb0c7175e75085b0) Review: IJ-CR-147924 GitOrigin-RevId: d23245bc5999332f117658240e89ed04e988c48f --- .../ide/ui/laf/darcula/DarculaNewUIUtil.kt | 16 +++++++ .../src/com/intellij/ui/WebAnimationUtils.kt | 48 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaNewUIUtil.kt b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaNewUIUtil.kt index bdfe07992adb..73544e69201c 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaNewUIUtil.kt +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaNewUIUtil.kt @@ -47,6 +47,22 @@ object DarculaNewUIUtil { } } + fun paintComponentBorder(g: Graphics, rect: Rectangle, color: Color, arc: Float, thick: Int) { + val g2 = g.create() as Graphics2D + + try { + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON) + g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, + if (MacUIUtil.USE_QUARTZ) RenderingHints.VALUE_STROKE_PURE else RenderingHints.VALUE_STROKE_NORMALIZE) + + g2.color = color + paintRectangle(g2, rect, arc, thick) + } + finally { + g2.dispose() + } + } + /** * Fills part of component inside border */ diff --git a/platform/platform-impl/src/com/intellij/ui/WebAnimationUtils.kt b/platform/platform-impl/src/com/intellij/ui/WebAnimationUtils.kt index 6f829aa42cf7..a1d2ec34b4f7 100644 --- a/platform/platform-impl/src/com/intellij/ui/WebAnimationUtils.kt +++ b/platform/platform-impl/src/com/intellij/ui/WebAnimationUtils.kt @@ -71,6 +71,54 @@ object WebAnimationUtils { return createSingleContentHtmlPage(body, background, componentId) } + fun createVideoHtmlPageWithUrl( + videoUrl: String, + background: Color, + stubImageUrl: String? = null, + autoplay: Boolean = true, + loop: Boolean = true, + injectedVideoEndedListener: String? = null, + ): String { + val componentId = "video" + val scriptText = + """ + document.addEventListener("DOMContentLoaded", function() { + let video = document.getElementById("$componentId"); + + window.playVideo = function() { + video.play(); + } + + window.pauseVideo = function() { + video.pause(); + } + + window.resetVideo = function() { + video.currentTime = 0; + } + ${if (injectedVideoEndedListener != null) """video.addEventListener('ended', function() { $injectedVideoEndedListener });""" else ""} + }); + """.trimIndent() + + val script = HtmlChunk.tag("script").addRaw(scriptText) + + val videoTag = HtmlChunk.tag("video") + .attr("id", componentId) + .let { if (autoplay) it.attr("autoplay") else it } + .let { if (loop) it.attr("loop") else it } + .attr("muted") + .let { if (stubImageUrl != null) it.attr("poster", stubImageUrl) else it } + .child(HtmlChunk.tag("source") + .attr("type", "video/webm") + .attr("src", videoUrl) + ) + val body = HtmlChunk.body() + .child(script) + .child(videoTag) + + return createSingleContentHtmlPage(body, background, componentId) + } + private fun createSingleContentHtmlPage(body: HtmlChunk, background: Color, componentId: String): String { val head = HtmlChunk.head().child(getSingleContentCssStyles(background, componentId)) return HtmlChunk.html()