CSS "background-color" style no longer affects natively rendered text fields
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Jun 2018 18:51:17 +0000 (18:51 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Jun 2018 18:51:17 +0000 (18:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=186597
<rdar://problem/41050528>

Reviewed by Tim Horton.

AppKit currently does not support rendering background color to the edges of a text field cell. This means that
in WebCore, when natively rendering text inputs with background color, we need to only draw the bezels of a text
field, such that the background color we paint behind the text field will be shown. Currently, the way we
accomplish this is by intercepting an internal NSTextField method that computes drawing options for CoreUI, and
inserting a `"borders only" => true` entry.

However, in a recent build of macOS Mojave, AppKit tweaked -_coreUIDrawOptionsWithFrame:inView:includeFocus: to
add an extra argument (such that it's now -_coreUIDrawOptionsWithFrame:inView:includeFocus:maskOnly:), which
negates the above workaround. To fix this in the short term, augment the workaround to apply to the latest macOS
Mojave as well. A longer-term fix is already tracked in <rdar://problem/11385461>, which would allow WebKit to
simply specify a background color on the text field cell, and have AppKit render it properly to the edges of the
bezels.

Covered by a test that is currently failing on Mojave: fast/forms/hidpi-textfield-background-bleeding.html

* rendering/RenderThemeMac.mm:
(-[WebCoreTextFieldCell _adjustedCoreUIDrawOptionsForDrawingBordersOnly:]):
(-[WebCoreTextFieldCell _coreUIDrawOptionsWithFrame:inView:includeFocus:]):
(-[WebCoreTextFieldCell _coreUIDrawOptionsWithFrame:inView:includeFocus:maskOnly:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232799 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderThemeMac.mm

index 9764376..007491d 100644 (file)
@@ -1,3 +1,31 @@
+2018-06-13  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        CSS "background-color" style no longer affects natively rendered text fields
+        https://bugs.webkit.org/show_bug.cgi?id=186597
+        <rdar://problem/41050528>
+
+        Reviewed by Tim Horton.
+
+        AppKit currently does not support rendering background color to the edges of a text field cell. This means that
+        in WebCore, when natively rendering text inputs with background color, we need to only draw the bezels of a text
+        field, such that the background color we paint behind the text field will be shown. Currently, the way we
+        accomplish this is by intercepting an internal NSTextField method that computes drawing options for CoreUI, and
+        inserting a `"borders only" => true` entry.
+
+        However, in a recent build of macOS Mojave, AppKit tweaked -_coreUIDrawOptionsWithFrame:inView:includeFocus: to
+        add an extra argument (such that it's now -_coreUIDrawOptionsWithFrame:inView:includeFocus:maskOnly:), which
+        negates the above workaround. To fix this in the short term, augment the workaround to apply to the latest macOS
+        Mojave as well. A longer-term fix is already tracked in <rdar://problem/11385461>, which would allow WebKit to
+        simply specify a background color on the text field cell, and have AppKit render it properly to the edges of the
+        bezels.
+
+        Covered by a test that is currently failing on Mojave: fast/forms/hidpi-textfield-background-bleeding.html
+
+        * rendering/RenderThemeMac.mm:
+        (-[WebCoreTextFieldCell _adjustedCoreUIDrawOptionsForDrawingBordersOnly:]):
+        (-[WebCoreTextFieldCell _coreUIDrawOptionsWithFrame:inView:includeFocus:]):
+        (-[WebCoreTextFieldCell _coreUIDrawOptionsWithFrame:inView:includeFocus:maskOnly:]):
+
 2018-06-13  Thibault Saunier  <tsaunier@igalia.com>
 
         [WPE] Build getUserMedia support
index 34fa174..a2e3ce7 100644 (file)
 // FIXME: This should go into an SPI.h file in the spi directory.
 @interface NSTextFieldCell ()
 - (CFDictionaryRef)_coreUIDrawOptionsWithFrame:(NSRect)cellFrame inView:(NSView *)controlView includeFocus:(BOOL)includeFocus;
+- (CFDictionaryRef)_coreUIDrawOptionsWithFrame:(NSRect)cellFrame inView:(NSView *)controlView includeFocus:(BOOL)includeFocus maskOnly:(BOOL)maskOnly;
 @end
 
 // FIXME: This should go into an SPI.h file in the spi directory.
@@ -153,15 +154,26 @@ static const double progressAnimationNumFrames = 256;
 
 @implementation WebCoreTextFieldCell
 
-- (CFDictionaryRef)_coreUIDrawOptionsWithFrame:(NSRect)cellFrame inView:(NSView *)controlView includeFocus:(BOOL)includeFocus
+- (CFDictionaryRef)_adjustedCoreUIDrawOptionsForDrawingBordersOnly:(CFDictionaryRef)defaultOptions
 {
-    // FIXME: This is a workaround for <rdar://problem/11385461>. When that bug is resolved, we should remove this code.
-    CFMutableDictionaryRef coreUIDrawOptions = CFDictionaryCreateMutableCopy(NULL, 0, [super _coreUIDrawOptionsWithFrame:cellFrame inView:controlView includeFocus:includeFocus]);
+    // FIXME: This is a workaround for <rdar://problem/11385461>. When that bug is resolved, we should remove this code,
+    // as well as the internal method overrides below.
+    CFMutableDictionaryRef coreUIDrawOptions = CFDictionaryCreateMutableCopy(NULL, 0, defaultOptions);
     CFDictionarySetValue(coreUIDrawOptions, CFSTR("borders only"), kCFBooleanTrue);
     CFAutorelease(coreUIDrawOptions);
     return coreUIDrawOptions;
 }
 
+- (CFDictionaryRef)_coreUIDrawOptionsWithFrame:(NSRect)cellFrame inView:(NSView *)controlView includeFocus:(BOOL)includeFocus
+{
+    return [self _adjustedCoreUIDrawOptionsForDrawingBordersOnly:[super _coreUIDrawOptionsWithFrame:cellFrame inView:controlView includeFocus:includeFocus]];
+}
+
+- (CFDictionaryRef)_coreUIDrawOptionsWithFrame:(NSRect)cellFrame inView:(NSView *)controlView includeFocus:(BOOL)includeFocus maskOnly:(BOOL)maskOnly
+{
+    return [self _adjustedCoreUIDrawOptionsForDrawingBordersOnly:[super _coreUIDrawOptionsWithFrame:cellFrame inView:controlView includeFocus:includeFocus maskOnly:maskOnly]];
+}
+
 @end
 
 @interface WebCoreRenderThemeBundle : NSObject