<rdar://problem/10542095> Focus rings are not drawn around push buttons, radio button...
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Dec 2011 18:15:02 +0000 (18:15 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Dec 2011 18:15:02 +0000 (18:15 +0000)
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.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/mac/ThemeMac.mm

index d3f9f2f677156db13f816aadc8e153e70872ec81..a69874aa0f9702f573c3ffb2171b3635a71b7803 100644 (file)
@@ -1,3 +1,20 @@
+2011-12-07  Dan Bernstein  <mitz@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  <bsalomon@google.com>
 
         [CHROMIUM/SKIA] Handle put[Un/Pre]multipliedImageData conversions in Skia rather than ImageBuffer
index e765d260920eddbc1df17e63bac492172f4c6333..e4c3db9d7fa688756fcfb78e8a3b7170a228f469 100644 (file)
@@ -69,6 +69,31 @@ using namespace std;
 
 @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 @@ static void updateStates(NSCell* cell, ControlStates states)
     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 @@ static void paintCheckbox(ControlStates states, GraphicsContext* context, const
         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 @@ static void paintRadio(ControlStates states, GraphicsContext* context, const Int
         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 @@ static void paintButton(ControlPart part, ControlStates states, GraphicsContext*
         [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])