Diff
Modified: trunk/Source/WebCore/ChangeLog (290982 => 290983)
--- trunk/Source/WebCore/ChangeLog 2022-03-08 09:13:25 UTC (rev 290982)
+++ trunk/Source/WebCore/ChangeLog 2022-03-08 09:25:40 UTC (rev 290983)
@@ -1,3 +1,26 @@
+2022-03-08 Carlos Garcia Campos <cgar...@igalia.com>
+
+ PDF.js content script is adding custom cocoa style unconditionally
+ https://bugs.webkit.org/show_bug.cgi?id=237516
+
+ Reviewed by Tim Nguyen.
+
+ Add the custom style from the WebKit code instead of injected content script to make it easier to add the style
+ depending on the platform. Move current cocoa specific style files to a cocoa directory.
+
+ * Modules/pdfjs-extras/cocoa/arrow.down.cir...@2x.png: Renamed from Source/WebCore/Modules/pdfjs-extras/arrow.down.cir...@2x.png.
+ * Modules/pdfjs-extras/cocoa/minus.magnifyinggl...@2x.png: Renamed from Source/WebCore/Modules/pdfjs-extras/minus.magnifyinggl...@2x.png.
+ * Modules/pdfjs-extras/cocoa/plus.magnifyinggl...@2x.png: Renamed from Source/WebCore/Modules/pdfjs-extras/plus.magnifyinggl...@2x.png.
+ * Modules/pdfjs-extras/cocoa/style.css: Renamed from Source/WebCore/Modules/pdfjs-extras/style-cocoa.css.
+ * Modules/pdfjs-extras/content-script.js:
+ (const.PDFJSContentScript.injectStyle): Deleted.
+ (const.PDFJSContentScript.init): Deleted.
+ * html/PDFDocument.cpp:
+ (WebCore::PDFDocumentEventListener::handleEvent):
+ (WebCore::PDFDocument::injectStyleAndContentScript):
+ (WebCore::PDFDocument::injectContentScript): Deleted.
+ * html/PDFDocument.h:
+
2022-03-08 Fujii Hironori <hironori.fu...@sony.com>
[WinCairo] GraphicsContextGL should have one more output texture for double buffering WebGL
Deleted: trunk/Source/WebCore/Modules/pdfjs-extras/arrow.down.cir...@2x.png
(Binary files differ)
Copied: trunk/Source/WebCore/Modules/pdfjs-extras/cocoa/arrow.down.cir...@2x.png (from rev 290982, trunk/Source/WebCore/Modules/pdfjs-extras/arrow.down.cir...@2x.png)
(Binary files differ)
Copied: trunk/Source/WebCore/Modules/pdfjs-extras/cocoa/minus.magnifyinggl...@2x.png (from rev 290982, trunk/Source/WebCore/Modules/pdfjs-extras/minus.magnifyinggl...@2x.png)
(Binary files differ)
Copied: trunk/Source/WebCore/Modules/pdfjs-extras/cocoa/plus.magnifyinggl...@2x.png (from rev 290982, trunk/Source/WebCore/Modules/pdfjs-extras/plus.magnifyinggl...@2x.png)
(Binary files differ)
Copied: trunk/Source/WebCore/Modules/pdfjs-extras/cocoa/style.css (from rev 290982, trunk/Source/WebCore/Modules/pdfjs-extras/style-cocoa.css) (0 => 290983)
--- trunk/Source/WebCore/Modules/pdfjs-extras/cocoa/style.css (rev 0)
+++ trunk/Source/WebCore/Modules/pdfjs-extras/cocoa/style.css 2022-03-08 09:25:40 UTC (rev 290983)
@@ -0,0 +1,249 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+body {
+ /* PDF.js variables */
+ --body-bg-color: rgb(128, 128, 128);
+ --scrollbar-color: auto;
+ --scrollbar-bg-color: auto;
+
+ /* Variables from WKPDFHUDView.mm */
+ --layerVerticalOffset: 40px;
+ --layerCornerRadius: 12px;
+ --layerGrayComponent: 0%;
+ --layerAlpha: 0.75;
+ --layerImageScale: 1.5;
+ --layerSeperatorControllerSize: 1.5px;
+ --layerControllerHorizontalMargin: calc(10px * var(--layerImageScale));
+ --layerImageVerticalMargin: 12px;
+ --controlLayerNormalAlpha: 0.75;
+ --controlLayerDownAlpha: 0.45;
+
+ --layerFadeInTimeInterval: 0.25s;
+ --layerFadeOutTimeInterval: 0.5s;
+ --initialHideTimeInterval: 3s;
+}
+
+@keyframes fade-out {
+ from {
+ opacity: 1;
+ }
+ to {
+ opacity: 0;
+ }
+}
+
+#loadingBar {
+ display: none !important;
+}
+
+#toolbarContainer {
+ display: contents;
+}
+
+#toolbarViewer {
+ position: fixed;
+ display: inline-flex;
+ left: 0;
+ right: 0;
+ width: fit-content;
+ height: auto;
+ margin: auto;
+
+ bottom: var(--layerVerticalOffset);
+ padding: var(--layerImageVerticalMargin) var(--layerControllerHorizontalMargin);
+ gap: var(--layerControllerHorizontalMargin);
+
+ background-color: hsla(0, 0%, var(--layerGrayComponent), var(--layerAlpha));
+ transition: var(--layerFadeInTimeInterval) opacity;
+ opacity: 0;
+ border-radius: var(--layerCornerRadius);
+ animation-name: fade-out;
+ animation-delay: var(--initialHideTimeInterval);
+ animation-duration: var(--layerFadeOutTimeInterval);
+ animation-fill-mode: backwards;
+}
+
+#toolbarViewer:hover {
+ transition: var(--layerFadeOutTimeInterval) opacity;
+ opacity: 1;
+}
+
+#toolbarViewerMiddle,
+#toolbarViewerRight,
+#toolbarViewerMiddle > .splitToolbarButton {
+ display: contents;
+}
+
+#toolbarViewerLeft,
+#toolbarViewerMiddle > *:not(.splitToolbarButton),
+#toolbarViewerRight > *:not(#download) {
+ display: none !important;
+}
+
+#toolbarViewer .toolbarButton {
+ width: calc(20px * var(--layerImageScale));
+ height: calc(20px * var(--layerImageScale));
+ padding: 0;
+ background-color: transparent;
+ background-size: contain;
+ background-position: center;
+ background-repeat: no-repeat;
+ opacity: var(--controlLayerNormalAlpha);
+}
+
+#toolbarViewer .toolbarButton:active {
+ opacity: var(--controlLayerDownAlpha);
+}
+
+#toolbarViewer .toolbarButton::before {
+ display: none !important;
+}
+
+#zoomOut {
+ order: 1;
+ background-image: url("./minus.magnifyinggl...@2x.png");
+}
+
+#zoomIn {
+ order: 2;
+ background-image: url("./plus.magnifyinggl...@2x.png");
+}
+
+#zoomOut + .splitToolbarButtonSeparator {
+ order: 3;
+ background-color: white;
+ opacity: 0.45;
+ width: var(--layerSeperatorControllerSize);
+ margin-top: -1px;
+ margin-bottom: -1px;
+}
+
+#download {
+ order: 4;
+ background-image: url("./arrow.down.cir...@2x.png");
+ display: block !important;
+}
+
+#viewerContainer {
+ top: 0;
+}
+
+/* Restyle PDF form fields */
+
+.annotationLayer :is(
+ .textWidgetAnnotation input,
+ .textWidgetAnnotation textarea,
+ .choiceWidgetAnnotation select,
+ .buttonWidgetAnnotation.checkBox input,
+ .buttonWidgetAnnotation.radioButton input,
+):not(:hover) {
+ --annotation-unfocused-field-background: none;
+}
+
+.annotationLayer :is(
+ .textWidgetAnnotation input,
+ .textWidgetAnnotation textarea,
+ .choiceWidgetAnnotation select,
+ .buttonWidgetAnnotation.checkBox input,
+ .buttonWidgetAnnotation.radioButton input,
+):hover {
+ border-color: transparent;
+}
+
+.annotationLayer :is(
+ .textWidgetAnnotation input,
+ .textWidgetAnnotation textarea,
+ .choiceWidgetAnnotation select,
+ .buttonWidgetAnnotation.checkBox input,
+ .buttonWidgetAnnotation.radioButton input,
+):focus {
+ --annotation-unfocused-field-background: none;
+ outline: -webkit-focus-ring-color 2px solid;
+ outline-offset: 2px;
+}
+
+/* Restyle the findbar */
+
+#findbar {
+ position: fixed;
+ top: 0;
+ left: 0;
+ right: 0;
+ margin: 0;
+ display: flex;
+ flex-direction: row-reverse;
+ background: var(--body-bg-color);
+ border-radius: 0;
+ box-shadow: none;
+
+ --main-color: rgba(249, 249, 250, 1);
+
+ --field-color: inherit;
+ --field-bg-color: rgba(0, 0, 0, 0.1);
+ --field-border-color: rgba(255,255,255,0.45);
+ --findbar-nextprevious-btn-bg-color: transparent;
+
+ --toggled-btn-color: rgba(255, 255, 255, 1);
+ --toggled-btn-bg-color: rgba(0, 0, 0, 0.3);
+ --button-hover-color: rgba(102, 102, 103, 1);
+ --toggled-hover-active-btn-color: rgba(0, 0, 0, 0.4);
+
+ --toolbar-icon-bg-color: rgba(255, 255, 255, 1);
+ --toolbar-icon-hover-bg-color: rgba(255, 255, 255, 1);
+}
+
+#findbar:not(.hidden) ~ #viewerContainer {
+ top: 32px;
+}
+
+#findbar::before,
+#findbar::after {
+ display: none;
+}
+
+#findbarOptionsTwoContainer {
+ display: contents;
+}
+
+#findResultsCount,
+#findMsg {
+ background-color: transparent !important;
+ color: inherit !important;
+}
+
+#findbar .splitToolbarButton > .toolbarButton::before {
+ rotate: -90deg;
+ top: 4px;
+}
+
+#findInput:focus {
+ border-color: rgba(0, 103, 244, 0.48);
+ outline: 2px solid rgba(0, 103, 244, 0.48);
+}
+
+#findInput[data-status="notFound"] {
+ background: var(--field-bg-color);
+ color: var(--field-color);
+}
Modified: trunk/Source/WebCore/Modules/pdfjs-extras/content-script.js (290982 => 290983)
--- trunk/Source/WebCore/Modules/pdfjs-extras/content-script.js 2022-03-08 09:13:25 UTC (rev 290982)
+++ trunk/Source/WebCore/Modules/pdfjs-extras/content-script.js 2022-03-08 09:25:40 UTC (rev 290983)
@@ -23,18 +23,7 @@
*/
const PDFJSContentScript = {
- injectStyle() {
- const stylesheet = document.createElement("link");
- stylesheet.rel = "stylesheet";
- stylesheet.href = ""
- document.head.appendChild(stylesheet);
- },
- init() {
- this.injectStyle();
- },
open(data) {
PDFViewerApplication.open(data);
}
};
-
-PDFJSContentScript.init();
Deleted: trunk/Source/WebCore/Modules/pdfjs-extras/minus.magnifyinggl...@2x.png
(Binary files differ)
Deleted: trunk/Source/WebCore/Modules/pdfjs-extras/plus.magnifyinggl...@2x.png
(Binary files differ)
Deleted: trunk/Source/WebCore/Modules/pdfjs-extras/style-cocoa.css (290982 => 290983)
--- trunk/Source/WebCore/Modules/pdfjs-extras/style-cocoa.css 2022-03-08 09:13:25 UTC (rev 290982)
+++ trunk/Source/WebCore/Modules/pdfjs-extras/style-cocoa.css 2022-03-08 09:25:40 UTC (rev 290983)
@@ -1,249 +0,0 @@
-/*
- * Copyright (C) 2022 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-body {
- /* PDF.js variables */
- --body-bg-color: rgb(128, 128, 128);
- --scrollbar-color: auto;
- --scrollbar-bg-color: auto;
-
- /* Variables from WKPDFHUDView.mm */
- --layerVerticalOffset: 40px;
- --layerCornerRadius: 12px;
- --layerGrayComponent: 0%;
- --layerAlpha: 0.75;
- --layerImageScale: 1.5;
- --layerSeperatorControllerSize: 1.5px;
- --layerControllerHorizontalMargin: calc(10px * var(--layerImageScale));
- --layerImageVerticalMargin: 12px;
- --controlLayerNormalAlpha: 0.75;
- --controlLayerDownAlpha: 0.45;
-
- --layerFadeInTimeInterval: 0.25s;
- --layerFadeOutTimeInterval: 0.5s;
- --initialHideTimeInterval: 3s;
-}
-
-@keyframes fade-out {
- from {
- opacity: 1;
- }
- to {
- opacity: 0;
- }
-}
-
-#loadingBar {
- display: none !important;
-}
-
-#toolbarContainer {
- display: contents;
-}
-
-#toolbarViewer {
- position: fixed;
- display: inline-flex;
- left: 0;
- right: 0;
- width: fit-content;
- height: auto;
- margin: auto;
-
- bottom: var(--layerVerticalOffset);
- padding: var(--layerImageVerticalMargin) var(--layerControllerHorizontalMargin);
- gap: var(--layerControllerHorizontalMargin);
-
- background-color: hsla(0, 0%, var(--layerGrayComponent), var(--layerAlpha));
- transition: var(--layerFadeInTimeInterval) opacity;
- opacity: 0;
- border-radius: var(--layerCornerRadius);
- animation-name: fade-out;
- animation-delay: var(--initialHideTimeInterval);
- animation-duration: var(--layerFadeOutTimeInterval);
- animation-fill-mode: backwards;
-}
-
-#toolbarViewer:hover {
- transition: var(--layerFadeOutTimeInterval) opacity;
- opacity: 1;
-}
-
-#toolbarViewerMiddle,
-#toolbarViewerRight,
-#toolbarViewerMiddle > .splitToolbarButton {
- display: contents;
-}
-
-#toolbarViewerLeft,
-#toolbarViewerMiddle > *:not(.splitToolbarButton),
-#toolbarViewerRight > *:not(#download) {
- display: none !important;
-}
-
-#toolbarViewer .toolbarButton {
- width: calc(20px * var(--layerImageScale));
- height: calc(20px * var(--layerImageScale));
- padding: 0;
- background-color: transparent;
- background-size: contain;
- background-position: center;
- background-repeat: no-repeat;
- opacity: var(--controlLayerNormalAlpha);
-}
-
-#toolbarViewer .toolbarButton:active {
- opacity: var(--controlLayerDownAlpha);
-}
-
-#toolbarViewer .toolbarButton::before {
- display: none !important;
-}
-
-#zoomOut {
- order: 1;
- background-image: url("./minus.magnifyinggl...@2x.png");
-}
-
-#zoomIn {
- order: 2;
- background-image: url("./plus.magnifyinggl...@2x.png");
-}
-
-#zoomOut + .splitToolbarButtonSeparator {
- order: 3;
- background-color: white;
- opacity: 0.45;
- width: var(--layerSeperatorControllerSize);
- margin-top: -1px;
- margin-bottom: -1px;
-}
-
-#download {
- order: 4;
- background-image: url("./arrow.down.cir...@2x.png");
- display: block !important;
-}
-
-#viewerContainer {
- top: 0;
-}
-
-/* Restyle PDF form fields */
-
-.annotationLayer :is(
- .textWidgetAnnotation input,
- .textWidgetAnnotation textarea,
- .choiceWidgetAnnotation select,
- .buttonWidgetAnnotation.checkBox input,
- .buttonWidgetAnnotation.radioButton input,
-):not(:hover) {
- --annotation-unfocused-field-background: none;
-}
-
-.annotationLayer :is(
- .textWidgetAnnotation input,
- .textWidgetAnnotation textarea,
- .choiceWidgetAnnotation select,
- .buttonWidgetAnnotation.checkBox input,
- .buttonWidgetAnnotation.radioButton input,
-):hover {
- border-color: transparent;
-}
-
-.annotationLayer :is(
- .textWidgetAnnotation input,
- .textWidgetAnnotation textarea,
- .choiceWidgetAnnotation select,
- .buttonWidgetAnnotation.checkBox input,
- .buttonWidgetAnnotation.radioButton input,
-):focus {
- --annotation-unfocused-field-background: none;
- outline: -webkit-focus-ring-color 2px solid;
- outline-offset: 2px;
-}
-
-/* Restyle the findbar */
-
-#findbar {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- margin: 0;
- display: flex;
- flex-direction: row-reverse;
- background: var(--body-bg-color);
- border-radius: 0;
- box-shadow: none;
-
- --main-color: rgba(249, 249, 250, 1);
-
- --field-color: inherit;
- --field-bg-color: rgba(0, 0, 0, 0.1);
- --field-border-color: rgba(255,255,255,0.45);
- --findbar-nextprevious-btn-bg-color: transparent;
-
- --toggled-btn-color: rgba(255, 255, 255, 1);
- --toggled-btn-bg-color: rgba(0, 0, 0, 0.3);
- --button-hover-color: rgba(102, 102, 103, 1);
- --toggled-hover-active-btn-color: rgba(0, 0, 0, 0.4);
-
- --toolbar-icon-bg-color: rgba(255, 255, 255, 1);
- --toolbar-icon-hover-bg-color: rgba(255, 255, 255, 1);
-}
-
-#findbar:not(.hidden) ~ #viewerContainer {
- top: 32px;
-}
-
-#findbar::before,
-#findbar::after {
- display: none;
-}
-
-#findbarOptionsTwoContainer {
- display: contents;
-}
-
-#findResultsCount,
-#findMsg {
- background-color: transparent !important;
- color: inherit !important;
-}
-
-#findbar .splitToolbarButton > .toolbarButton::before {
- rotate: -90deg;
- top: 4px;
-}
-
-#findInput:focus {
- border-color: rgba(0, 103, 244, 0.48);
- outline: 2px solid rgba(0, 103, 244, 0.48);
-}
-
-#findInput[data-status="notFound"] {
- background: var(--field-bg-color);
- color: var(--field-color);
-}
Modified: trunk/Source/WebCore/html/PDFDocument.cpp (290982 => 290983)
--- trunk/Source/WebCore/html/PDFDocument.cpp 2022-03-08 09:13:25 UTC (rev 290982)
+++ trunk/Source/WebCore/html/PDFDocument.cpp 2022-03-08 09:25:40 UTC (rev 290983)
@@ -33,8 +33,10 @@
#include "Frame.h"
#include "HTMLAnchorElement.h"
#include "HTMLBodyElement.h"
+#include "HTMLHeadElement.h"
#include "HTMLHtmlElement.h"
#include "HTMLIFrameElement.h"
+#include "HTMLLinkElement.h"
#include "HTMLNames.h"
#include "HTMLScriptElement.h"
#include "RawDataDocumentParser.h"
@@ -109,7 +111,7 @@
void PDFDocumentEventListener::handleEvent(ScriptExecutionContext&, Event& event)
{
if (is<HTMLIFrameElement>(event.target()) && event.type() == eventNames().loadEvent) {
- m_document->injectContentScript();
+ m_document->injectStyleAndContentScript();
} else if (is<HTMLScriptElement>(event.target()) && event.type() == eventNames().loadEvent) {
m_document->setContentScriptLoaded(true);
if (m_document->isFinishedParsing())
@@ -204,11 +206,18 @@
call(globalObject, openFunction, callData, globalObject, arguments);
}
-void PDFDocument::injectContentScript()
+void PDFDocument::injectStyleAndContentScript()
{
- auto contentDocument = m_iframe->contentDocument();
+ auto* contentDocument = m_iframe->contentDocument();
+ ASSERT(contentDocument->head());
+ auto link = HTMLLinkElement::create(HTMLNames::linkTag, *contentDocument, false);
+ link->setAttribute(relAttr, "stylesheet"_s);
+#if PLATFORM(COCOA)
+ link->setAttribute(hrefAttr, "webkit-pdfjs-viewer://pdfjs/extras/cocoa/style.css"_s);
+#endif
+ contentDocument->head()->appendChild(link);
+
ASSERT(contentDocument->body());
-
auto script = HTMLScriptElement::create(scriptTag, *contentDocument, false);
script->addEventListener("load", m_listener.releaseNonNull(), false);
Modified: trunk/Source/WebCore/html/PDFDocument.h (290982 => 290983)
--- trunk/Source/WebCore/html/PDFDocument.h 2022-03-08 09:13:25 UTC (rev 290982)
+++ trunk/Source/WebCore/html/PDFDocument.h 2022-03-08 09:25:40 UTC (rev 290983)
@@ -41,7 +41,7 @@
void updateDuringParsing();
void finishedParsing();
- void injectContentScript();
+ void injectStyleAndContentScript();
void sendPDFArrayBuffer();
bool isFinishedParsing() const { return m_isFinishedParsing; }