Backgrounds bleed out of natively rendered text fields
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Oct 2015 15:18:42 +0000 (15:18 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Oct 2015 15:18:42 +0000 (15:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=149843
<rdar://problem/22896977>

Reviewed by Darin Adler.

Source/WebCore:

When natively rendering a text field with a background on Mac, the background bleeds out
of the text field's border when the graphics context is scaled (as a result of a retina
display or zoom/scale effects). This is because when we render the text field in bezeled
style within a certain frame, AppKit adds 1 device pixel insets on all sides of the frame,
which renders a text field that is slightly smaller than the frame. To adjust for this, we
inflate the paint rect.

Test: fast/forms/hidpi-textfield-background-bleeding.html

* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::paintTextField):

LayoutTests:

Add a layout test to check that the background of a natively rendered text field
cell does not bleed.

* TestExpectations:
* fast/forms/hidpi-textfield-background-bleeding-expected.html: Added.
* fast/forms/hidpi-textfield-background-bleeding.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/forms/hidpi-textfield-background-bleeding-expected.html [new file with mode: 0644]
LayoutTests/fast/forms/hidpi-textfield-background-bleeding.html [new file with mode: 0644]
LayoutTests/platform/ios-simulator/TestExpectations
LayoutTests/platform/mac/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderThemeMac.mm

index 549c3bb..30ee0aa 100644 (file)
@@ -1,3 +1,18 @@
+2015-10-08  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Backgrounds bleed out of natively rendered text fields
+        https://bugs.webkit.org/show_bug.cgi?id=149843
+        <rdar://problem/22896977>
+
+        Reviewed by Darin Adler.
+
+        Add a layout test to check that the background of a natively rendered text field
+        cell does not bleed.
+
+        * TestExpectations:
+        * fast/forms/hidpi-textfield-background-bleeding-expected.html: Added.
+        * fast/forms/hidpi-textfield-background-bleeding.html: Added.
+
 2015-10-08  Nikita Vasilyev  <nvasilyev@apple.com>
 
         Web Inspector: Stack trace view doesn't properly display lines without function names
diff --git a/LayoutTests/fast/forms/hidpi-textfield-background-bleeding-expected.html b/LayoutTests/fast/forms/hidpi-textfield-background-bleeding-expected.html
new file mode 100644 (file)
index 0000000..335c207
--- /dev/null
@@ -0,0 +1,24 @@
+<html>
+<head>
+    <style>
+    body {
+        margin: 0;
+    }
+
+    div {
+        position: absolute;
+        top: 0;
+        left: 0;
+        border: 0.5px black solid;
+        width: 99px;
+        height: 99px;
+        background-color: yellow;
+    }
+    </style>
+</head>
+
+<body>
+    <div />
+</body>
+
+</html>
diff --git a/LayoutTests/fast/forms/hidpi-textfield-background-bleeding.html b/LayoutTests/fast/forms/hidpi-textfield-background-bleeding.html
new file mode 100644 (file)
index 0000000..b1b1ee1
--- /dev/null
@@ -0,0 +1,28 @@
+<html>
+<head>
+    <style>
+    div, input {
+        position: absolute;
+        top: 0;
+        left: 0;
+    }
+
+    input {
+        background-color: yellow;
+        width: 100px;
+        height: 100px;
+    }
+
+    div {
+        border: 0.5px black solid;
+        width: 99px;
+        height: 99px;
+    }
+    </style>
+</head>
+
+<body>
+    <input /><div />
+</body>
+
+</html>
index 7b40a41..3481766 100644 (file)
@@ -1714,6 +1714,7 @@ fast/forms/file/input-file-write-files.html [ Failure ]
 fast/forms/focus-change-on-keypress.html [ Failure ]
 fast/forms/focus-selection-input.html [ Failure ]
 fast/forms/hidpi-textarea-on-subpixel-position.html [ ImageOnlyFailure ]
+fast/forms/hidpi-textfield-background-bleeding.html [ ImageOnlyFailure ]
 fast/forms/implicit-submission.html [ Failure ]
 fast/forms/input-baseline.html [ Failure ]
 fast/forms/input-first-letter-edit.html [ ImageOnlyFailure ]
index ba422eb..73f7a13 100644 (file)
@@ -728,6 +728,9 @@ webkit.org/b/124321 animations/resume-after-page-cache.html [ Pass Failure ]
 
 webkit.org/b/147254 media/restore-from-page-cache.html [ Pass Failure ]
 
+# After Mavericks, native text fields are rendered slightly smaller, causing backgrounds to bleed on platforms.
+[ Mavericks ] fast/forms/hidpi-textfield-background-bleeding.html [ ImageOnlyFailure ]
+
 # These fast/forms/select tests open a pop-up menu (visible on screen even when using run-webkit-tests), and get stuck in its nested event loop.
 webkit.org/b/87748 fast/forms/select/optgroup-clicking.html [ Skip ]
 webkit.org/b/73304 fast/forms/select/menulist-popup-crash.html [ Skip ]
index 5c172bd..9856707 100644 (file)
@@ -1,3 +1,23 @@
+2015-10-08  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Backgrounds bleed out of natively rendered text fields
+        https://bugs.webkit.org/show_bug.cgi?id=149843
+        <rdar://problem/22896977>
+
+        Reviewed by Darin Adler.
+
+        When natively rendering a text field with a background on Mac, the background bleeds out
+        of the text field's border when the graphics context is scaled (as a result of a retina
+        display or zoom/scale effects). This is because when we render the text field in bezeled
+        style within a certain frame, AppKit adds 1 device pixel insets on all sides of the frame,
+        which renders a text field that is slightly smaller than the frame. To adjust for this, we
+        inflate the paint rect.
+
+        Test: fast/forms/hidpi-textfield-background-bleeding.html
+
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::paintTextField):
+
 2015-10-09  Xabier Rodriguez Calvar  <calvaris@igalia.com> and Youenn Fablet  <youenn.fablet@crf.canon.fr>
 
         Refactor WebCore JS builtins to prepare for automatic generation
index 4643795..d8af3d2 100644 (file)
@@ -853,12 +853,20 @@ bool RenderThemeMac::paintTextField(const RenderObject& o, const PaintInfo& pain
 {
     LocalCurrentGraphicsContext localContext(paintInfo.context());
 
+    // <rdar://problem/22896977> We adjust the paint rect here to account for how AppKit draws the text
+    // field cell slightly smaller than the rect we pass to drawWithFrame.
+    FloatRect adjustedPaintRect(r);
+    AffineTransform transform = paintInfo.context().getCTM();
+    if (transform.xScale() > 1 || transform.yScale() > 1) {
+        adjustedPaintRect.inflateX(1 / transform.xScale());
+        adjustedPaintRect.inflateY(1 / transform.yScale());
+    }
     NSTextFieldCell *textField = this->textField();
 
     GraphicsContextStateSaver stateSaver(paintInfo.context());
 
     [textField setEnabled:(isEnabled(o) && !isReadOnlyControl(o))];
-    [textField drawWithFrame:NSRect(r) inView:documentViewFor(o)];
+    [textField drawWithFrame:NSRect(adjustedPaintRect) inView:documentViewFor(o)];
 
     [textField setControlView:nil];