Skip to content

Commit 8a4cbc9

Browse files
committed
REGRESSION(306364@main): Form fields in PDFs in dark mode are not readable
https://bugs.webkit.org/show_bug.cgi?id=308793 rdar://171198060 Reviewed by Richard Robinson. After 306364@main, PDF annotation elements respect light/dark color scheme, but we also respect the text annotation's font color. Since PDF content is ordinarily for light mode, the prescribed annotation font color is dark, which clashes with our text annotation's dark background color (in dark mode). To fix this issue, we simply opt out of dark mode adaptations for PDF annotations. Tests: TestWebKitAPI.UnifiedPDF.TextAnnotationBackgroundColorDoesNotAdaptToColorScheme * Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.mm: (WebKit::PDFPluginBase::annotationStyle const): * Tools/TestWebKitAPI/PlatformUtilities.h: * Tools/TestWebKitAPI/Tests/WebKitCocoa/UnifiedPDFTests.mm: (TestWebKitAPI::UNIFIED_PDF_TEST): * Tools/TestWebKitAPI/cocoa/PlatformUtilitiesCocoa.mm: (TestWebKitAPI::Util::toSTD): Canonical link: https://commits.webkit.org/308330@main
1 parent 58cfbf6 commit 8a4cbc9

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,7 @@ static void verboseLog(PDFIncrementalLoader* incrementalLoader, std::optional<ui
15801580
".annotation {"
15811581
" position: absolute;"
15821582
" pointer-events: auto;"
1583+
" color-scheme: only light;"
15831584
"}"
15841585
""
15851586
"textarea.annotation { "

Tools/TestWebKitAPI/PlatformUtilities.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ ALWAYS_INLINE std::string toSTD(const String& string) { return toSTD(string.utf8
6464

6565
#if USE(FOUNDATION)
6666
std::string toSTD(NSString *);
67+
std::string toSTD(RetainPtr<NSString>);
6768
bool jsonMatchesExpectedValues(NSString *jsonString, NSDictionary *expected);
6869
#ifdef __OBJC__
6970
void waitForConditionWithLogging(std::function<bool()>&&, NSTimeInterval loggingTimeout, NSString *message, ...) NS_FORMAT_FUNCTION(3, 4);

Tools/TestWebKitAPI/Tests/WebKitCocoa/UnifiedPDFTests.mm

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#import "WKWebViewForTestingImmediateActions.h"
5050
#import <WebCore/Color.h>
5151
#import <WebCore/ColorSerialization.h>
52+
#import <WebCore/IntPoint.h>
5253
#import <WebCore/WebEvent.h>
5354
#import <WebKit/WKNavigationDelegatePrivate.h>
5455
#import <WebKit/WKPreferencesPrivate.h>
@@ -371,6 +372,46 @@ void pressKey(auto key, unsigned short code, Seconds duration = 200_ms)
371372
EXPECT_EQ(colorsBeforeHover, colorsAfterHover);
372373
}
373374

375+
UNIFIED_PDF_TEST(TextAnnotationBackgroundColorDoesNotAdaptToColorScheme)
376+
{
377+
RetainPtr webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 600, 600) configuration:configurationForWebViewTestingUnifiedPDF().get() addToWindow:YES]);
378+
RetainPtr request = [NSURLRequest requestWithURL:[NSBundle.test_resourcesBundle URLForResource:@"textInput" withExtension:@"pdf"]];
379+
[webView synchronouslyLoadRequest:request.get()];
380+
[[webView window] makeFirstResponder:webView.get()];
381+
[[webView window] makeKeyAndOrderFront:nil];
382+
[[webView window] orderFrontRegardless];
383+
384+
auto evaluateAnnotationBackgroundColor = [&webView] {
385+
static constexpr WebCore::IntPoint annotationPoint { 200, 200 };
386+
[webView mouseMoveToPoint:annotationPoint withFlags:0];
387+
[webView sendClickAtPoint:annotationPoint];
388+
[webView waitForPendingMouseEvents];
389+
[webView waitForNextPresentationUpdate];
390+
391+
RetainPtr backgroundColor = [webView stringByEvaluatingJavaScript:@"getComputedStyle(document.querySelector('#annotationContainer > input')).backgroundColor"];
392+
393+
static constexpr WebCore::IntPoint blankPoint { 50, 50 };
394+
[webView mouseMoveToPoint:blankPoint withFlags:0];
395+
[webView sendClickAtPoint:blankPoint];
396+
[webView waitForPendingMouseEvents];
397+
[webView waitForNextPresentationUpdate];
398+
399+
return backgroundColor;
400+
};
401+
402+
[webView forceLightMode];
403+
[webView waitForNextPresentationUpdate];
404+
405+
RetainPtr lightModeColor = evaluateAnnotationBackgroundColor();
406+
407+
[webView forceDarkMode];
408+
[webView waitForNextPresentationUpdate];
409+
410+
RetainPtr darkModeColor = evaluateAnnotationBackgroundColor();
411+
412+
EXPECT_WK_STREQ(lightModeColor, darkModeColor);
413+
}
414+
374415
#endif // PLATFORM(MAC)
375416

376417
#if ENABLE(PDF_HUD)

Tools/TestWebKitAPI/cocoa/PlatformUtilitiesCocoa.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@
6464
return std::string(buffer.get(), stringLength);
6565
}
6666

67+
std::string toSTD(RetainPtr<NSString> string)
68+
{
69+
return toSTD(string.get());
70+
}
71+
6772
bool jsonMatchesExpectedValues(NSString *jsonString, NSDictionary *expected)
6873
{
6974
NSError *error = nil;

0 commit comments

Comments
 (0)