Title: [102246] trunk/Source/WebCore
Revision
102246
Author
m...@apple.com
Date
2011-12-07 10:15:02 -0800 (Wed, 07 Dec 2011)

Log Message

<rdar://problem/10542095> Focus rings are not drawn around push buttons, radio buttons and checkboxes

Reviewed by Darin Adler.

Instead of relying on -setShowsFirstResponder: to make -drawWithFrame:inView: draw the focus
ring, use -drawFocusRingMaskWithFrame:inView:.

* platform/mac/ThemeMac.mm:
(-[NSCell _web_drawFocusRingWithFrame:inView:]): Added. Sets up the focus ring style and a
transparency layer, then uses -drawFocusRingMaskWithFrame:inView: to draw the focus ring.
(WebCore::updateStates): Eliminated calls to get and set showsFirstResponder.
(WebCore::paintCheckbox): Changed to use -_web_drawFocusRingWithFrame:inView:.
(WebCore::paintRadio): Ditto.
(WebCore::paintButton): Ditto.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (102245 => 102246)


--- trunk/Source/WebCore/ChangeLog	2011-12-07 18:12:47 UTC (rev 102245)
+++ trunk/Source/WebCore/ChangeLog	2011-12-07 18:15:02 UTC (rev 102246)
@@ -1,3 +1,20 @@
+2011-12-07  Dan Bernstein  <m...@apple.com>
+
+        <rdar://problem/10542095> Focus rings are not drawn around push buttons, radio buttons and checkboxes
+
+        Reviewed by Darin Adler.
+
+        Instead of relying on -setShowsFirstResponder: to make -drawWithFrame:inView: draw the focus
+        ring, use -drawFocusRingMaskWithFrame:inView:.
+
+        * platform/mac/ThemeMac.mm:
+        (-[NSCell _web_drawFocusRingWithFrame:inView:]): Added. Sets up the focus ring style and a
+        transparency layer, then uses -drawFocusRingMaskWithFrame:inView: to draw the focus ring.
+        (WebCore::updateStates): Eliminated calls to get and set showsFirstResponder.
+        (WebCore::paintCheckbox): Changed to use -_web_drawFocusRingWithFrame:inView:.
+        (WebCore::paintRadio): Ditto.
+        (WebCore::paintButton): Ditto.
+
 2011-12-07  Brian Salomon  <bsalo...@google.com>
 
         [CHROMIUM/SKIA] Handle put[Un/Pre]multipliedImageData conversions in Skia rather than ImageBuffer

Modified: trunk/Source/WebCore/platform/mac/ThemeMac.mm (102245 => 102246)


--- trunk/Source/WebCore/platform/mac/ThemeMac.mm	2011-12-07 18:12:47 UTC (rev 102245)
+++ trunk/Source/WebCore/platform/mac/ThemeMac.mm	2011-12-07 18:15:02 UTC (rev 102246)
@@ -69,6 +69,31 @@
 
 @end
 
+#define BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING defined(BUILDING_ON_SNOW_LEOPARD) || defined(BUILDING_ON_LION)
+
+#if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING
+
+@interface NSCell (WebFocusRingDrawing)
+- (void)_web_drawFocusRingWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
+@end
+
+@implementation NSCell (WebFocusRingDrawing)
+
+- (void)_web_drawFocusRingWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
+{
+    CGContextRef cgContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
+    CGContextSaveGState(cgContext);
+    NSSetFocusRingStyle(NSFocusRingOnly);
+    CGContextBeginTransparencyLayerWithRect(cgContext, NSRectToCGRect(cellFrame), 0);
+    [self drawFocusRingMaskWithFrame:cellFrame inView:controlView];
+    CGContextEndTransparencyLayer(cgContext);
+    CGContextRestoreGState(cgContext);
+}
+
+@end
+
+#endif
+
 // FIXME: Default buttons really should be more like push buttons and not like buttons.
 
 namespace WebCore {
@@ -150,11 +175,13 @@
     if (enabled != oldEnabled)
         [cell setEnabled:enabled];
     
+#if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING
     // Focused state
     bool oldFocused = [cell showsFirstResponder];
     bool focused = states & FocusState;
     if (focused != oldFocused)
         [cell setShowsFirstResponder:focused];
+#endif
 
     // Checked and Indeterminate
     bool oldIndeterminate = [cell state] == NSMixedState;
@@ -275,8 +302,13 @@
         context->scale(FloatSize(zoomFactor, zoomFactor));
         context->translate(-inflatedRect.x(), -inflatedRect.y());
     }
-    
-    [checkboxCell drawWithFrame:NSRect(inflatedRect) inView:ThemeMac::ensuredView(scrollView)];
+
+    NSView *view = ThemeMac::ensuredView(scrollView);
+    [checkboxCell drawWithFrame:NSRect(inflatedRect) inView:view];
+#if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING
+    if (states & FocusState)
+        [checkboxCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view];
+#endif
     [checkboxCell setControlView:nil];
     
     END_BLOCK_OBJC_EXCEPTIONS
@@ -351,9 +383,14 @@
         context->scale(FloatSize(zoomFactor, zoomFactor));
         context->translate(-inflatedRect.x(), -inflatedRect.y());
     }
-    
+
     BEGIN_BLOCK_OBJC_EXCEPTIONS
-    [radioCell drawWithFrame:NSRect(inflatedRect) inView:ThemeMac::ensuredView(scrollView)];
+    NSView *view = ThemeMac::ensuredView(scrollView);
+    [radioCell drawWithFrame:NSRect(inflatedRect) inView:view];
+#if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING
+    if (states & FocusState)
+        [radioCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view];
+#endif
     [radioCell setControlView:nil];
     END_BLOCK_OBJC_EXCEPTIONS
 }
@@ -482,6 +519,10 @@
         [window setDefaultButtonCell:nil];
 
     [buttonCell drawWithFrame:NSRect(inflatedRect) inView:view];
+#if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING
+    if (states & FocusState)
+        [buttonCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view];
+#endif
     [buttonCell setControlView:nil];
 
     if (![previousDefaultButtonCell isEqual:buttonCell])
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to