+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
@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 {
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;
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
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
}
[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])