Title: [116697] trunk/Source/WebCore
Revision
116697
Author
[email protected]
Date
2012-05-10 15:58:28 -0700 (Thu, 10 May 2012)

Log Message

https://bugs.webkit.org/show_bug.cgi?id=82131
[Mac] REGRESSION (r110480): Text field that specifies background-color 
(or is auto-filled) gets un-themed border
-and corresponding-
<rdar://problem/11115221>

Reviewed by Maciej Stachowiak.

This change rolls out r110480 which is what caused styled text fields 
to get the un-themed border, and it does a bunch of work to make sure 
we get the pretty, new version of the NSTextField art whenever 
possible. We do this differently for post-Lion OS's since there is now 
a way to opt into it all the time. Lion and SnowLeopard can only use 
the new art in HiDPI mode when the background color of the text field 
is just white.

RenderThemeMac::textField() takes a boolean paramter used to determine 
if the new gradient will be used.
* rendering/RenderThemeMac.h:
(RenderThemeMac):
        
This is the post-Lion workaround. This code has no effect on Lion and 
SnowLeopard. This allows up to opt into a version of [NSTextField drawWithFrame:] that will only draw the frame of the text field; without this, it will draw the frame and the background, which creates a number of problems with styled text fields and text fields in HiDPI. There is a less comprehesive workaround for Lion and SnowLeopard in place in RenderThemeMac::textField().
* rendering/RenderThemeMac.mm:
(-[WebCoreTextFieldCell _coreUIDrawOptionsWithFrame:inView:includeFocus:]):
        
This is the roll-out of r110480.
(WebCore::RenderThemeMac::isControlStyled):
        
See the comments for a full explanation, but this is mostly code for 
Lion and SnowLeopard to determine if we can opt into the new artwork.
(WebCore::RenderThemeMac::paintTextField):
(WebCore::RenderThemeMac::textField):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (116696 => 116697)


--- trunk/Source/WebCore/ChangeLog	2012-05-10 22:55:03 UTC (rev 116696)
+++ trunk/Source/WebCore/ChangeLog	2012-05-10 22:58:28 UTC (rev 116697)
@@ -1,3 +1,39 @@
+2012-05-10  Beth Dakin  <[email protected]>
+
+        https://bugs.webkit.org/show_bug.cgi?id=82131
+        [Mac] REGRESSION (r110480): Text field that specifies background-color 
+        (or is auto-filled) gets un-themed border
+        -and corresponding-
+        <rdar://problem/11115221>
+
+        Reviewed by Maciej Stachowiak.
+
+        This change rolls out r110480 which is what caused styled text fields 
+        to get the un-themed border, and it does a bunch of work to make sure 
+        we get the pretty, new version of the NSTextField art whenever 
+        possible. We do this differently for post-Lion OS's since there is now 
+        a way to opt into it all the time. Lion and SnowLeopard can only use 
+        the new art in HiDPI mode when the background color of the text field 
+        is just white.
+
+        RenderThemeMac::textField() takes a boolean paramter used to determine 
+        if the new gradient will be used.
+        * rendering/RenderThemeMac.h:
+        (RenderThemeMac):
+        
+        This is the post-Lion workaround. This code has no effect on Lion and 
+        SnowLeopard. This allows up to opt into a version of [NSTextField drawWithFrame:] that will only draw the frame of the text field; without this, it will draw the frame and the background, which creates a number of problems with styled text fields and text fields in HiDPI. There is a less comprehesive workaround for Lion and SnowLeopard in place in RenderThemeMac::textField().
+        * rendering/RenderThemeMac.mm:
+        (-[WebCoreTextFieldCell _coreUIDrawOptionsWithFrame:inView:includeFocus:]):
+        
+        This is the roll-out of r110480.
+        (WebCore::RenderThemeMac::isControlStyled):
+        
+        See the comments for a full explanation, but this is mostly code for 
+        Lion and SnowLeopard to determine if we can opt into the new artwork.
+        (WebCore::RenderThemeMac::paintTextField):
+        (WebCore::RenderThemeMac::textField):
+
 2012-05-10  Anders Carlsson  <[email protected]>
 
         WebKit1: Add a way to blacklist specific plug-ins/plug-in versions

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.h (116696 => 116697)


--- trunk/Source/WebCore/rendering/RenderThemeMac.h	2012-05-10 22:55:03 UTC (rev 116696)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.h	2012-05-10 22:58:28 UTC (rev 116697)
@@ -219,7 +219,7 @@
     NSMenu* searchMenuTemplate() const;
     NSSliderCell* sliderThumbHorizontal() const;
     NSSliderCell* sliderThumbVertical() const;
-    NSTextFieldCell* textField() const;
+    NSTextFieldCell* textField(bool useNewGradient) const;
 
 #if ENABLE(METER_TAG)
     NSLevelIndicatorStyle levelIndicatorStyleFor(ControlPart) const;

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (116696 => 116697)


--- trunk/Source/WebCore/rendering/RenderThemeMac.mm	2012-05-10 22:55:03 UTC (rev 116696)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm	2012-05-10 22:58:28 UTC (rev 116697)
@@ -105,6 +105,25 @@
 
 @end
 
+@interface NSTextFieldCell (WKDetails)
+- (CFDictionaryRef)_coreUIDrawOptionsWithFrame:(NSRect)cellFrame inView:(NSView *)controlView includeFocus:(BOOL)includeFocus;
+@end
+
+
+@interface WebCoreTextFieldCell : NSTextFieldCell
+- (CFDictionaryRef)_coreUIDrawOptionsWithFrame:(NSRect)cellFrame inView:(NSView *)controlView includeFocus:(BOOL)includeFocus;
+@end
+
+@implementation WebCoreTextFieldCell
+- (CFDictionaryRef)_coreUIDrawOptionsWithFrame:(NSRect)cellFrame inView:(NSView *)controlView includeFocus:(BOOL)includeFocus
+{
+    // FIXME: This is a post-Lion-only 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]);
+    CFDictionarySetValue(coreUIDrawOptions, @"borders only", kCFBooleanTrue);
+    return (CFDictionaryRef)[NSMakeCollectable(coreUIDrawOptions) autorelease];
+}
+@end
+
 namespace WebCore {
 
 using namespace HTMLNames;
@@ -489,7 +508,7 @@
 bool RenderThemeMac::isControlStyled(const RenderStyle* style, const BorderData& border,
                                      const FillLayer& background, const Color& backgroundColor) const
 {
-    if (style->appearance() == TextAreaPart || style->appearance() == ListboxPart)
+    if (style->appearance() == TextFieldPart || style->appearance() == TextAreaPart || style->appearance() == ListboxPart)
         return style->border() != border;
         
     // FIXME: This is horrible, but there is not much else that can be done.  Menu lists cannot draw properly when
@@ -714,8 +733,20 @@
 bool RenderThemeMac::paintTextField(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
 {
     LocalCurrentGraphicsContext localContext(paintInfo.context);
-    NSTextFieldCell* textField = this->textField();
 
+    bool useNewGradient = true;
+#if defined(BUILDING_ON_LION) || defined(BUILDING_ON_SNOW_LEOPARD)
+    // See comment in RenderThemeMac::textField() for a complete explanation of this.
+    useNewGradient = WebCore::deviceScaleFactor(o->frame()) != 1;
+    if (useNewGradient) {
+        useNewGradient = o->style()->hasAppearance()
+            && o->style()->visitedDependentColor(CSSPropertyBackgroundColor) == Color::white
+            && !o->style()->hasBackgroundImage();
+    }
+#endif
+
+    NSTextFieldCell* textField = this->textField(useNewGradient);
+
     GraphicsContextStateSaver stateSaver(*paintInfo.context);
 
     [textField setEnabled:(isEnabled(o) && !isReadOnlyControl(o))];
@@ -2133,15 +2164,36 @@
     return m_sliderThumbVertical.get();
 }
 
-NSTextFieldCell* RenderThemeMac::textField() const
+NSTextFieldCell* RenderThemeMac::textField(bool useNewGradient) const
 {
     if (!m_textField) {
-        m_textField.adoptNS([[NSTextFieldCell alloc] initTextCell:@""]);
+        m_textField.adoptNS([[WebCoreTextFieldCell alloc] initTextCell:@""]);
         [m_textField.get() setBezeled:YES];
         [m_textField.get() setEditable:YES];
         [m_textField.get() setFocusRingType:NSFocusRingTypeExterior];
+#if defined(BUILDING_ON_LION) || defined(BUILDING_ON_SNOW_LEOPARD)
+        [m_textField.get() setDrawsBackground:YES];
+#else
+        UNUSED_PARAM(useNewGradient);
+        [m_textField.get() setDrawsBackground:NO];
+#endif
     }
 
+#if defined(BUILDING_ON_LION) || defined(BUILDING_ON_SNOW_LEOPARD)
+    // This is a workaround for <rdar://problem/11385461> on Lion and SnowLeopard. Newer versions of the
+    // OS can always use the newer version of the text field with the workaround above in
+    // _coreUIDrawOptionsWithFrame. With this workaround for older OS's, when the deviceScaleFactor is 1,
+    // we have an old-school gradient bezel in text fields whether they are styled or not. This is fine and
+    // matches shipping Safari. When the deviceScaleFactor is greater than 1, text fields will have newer,
+    // AppKit-matching gradients that look much more appropriate at the higher resolutions. However, if the
+    // text field is styled  in any way, we'll revert to the old-school bezel, which doesn't look great in
+    // HiDPI, but it looks better than the CSS border, which is the only alternative until 11385461 is resolved.
+    if (useNewGradient)
+        [m_textField.get() setBackgroundColor:[NSColor whiteColor]];
+    else
+        [m_textField.get() setBackgroundColor:[NSColor clearColor]];
+#endif
+
     return m_textField.get();
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to