return false;
}
-static void paintToggleButton(ControlPart buttonType, ControlStates& controlStates, GraphicsContext* context, const FloatRect& zoomedRect, float zoomFactor, ScrollView* scrollView)
+static void paintToggleButton(ControlPart buttonType, ControlStates& controlStates, GraphicsContext* context, const FloatRect& zoomedRect, float zoomFactor, ScrollView* scrollView, float deviceScaleFactor, float pageScaleFactor)
{
BEGIN_BLOCK_OBJC_EXCEPTIONS
#endif
NSView *view = ThemeMac::ensuredView(scrollView, controlStates, useUnparentedView);
- bool isAnimating = false;
bool needsRepaint = false;
+ bool useImageBuffer = pageScaleFactor != 1.0f || zoomFactor != 1.0f;
+ bool isCellFocused = controlStates.states() & ControlStates::FocusState;
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
if ([toggleButtonCell _stateAnimationRunning]) {
context->translate(0, -inflatedRect.height());
[toggleButtonCell _renderCurrentAnimationFrameInContext:context->platformContext() atLocation:NSMakePoint(0, 0)];
- isAnimating = [toggleButtonCell _stateAnimationRunning];
+ if (![toggleButtonCell _stateAnimationRunning] && isCellFocused)
+ needsRepaint = ThemeMac::drawCellOrFocusRingWithViewIntoContext(toggleButtonCell, context, inflatedRect, view, false, true, useImageBuffer, deviceScaleFactor);
} else
- [toggleButtonCell drawWithFrame:NSRect(inflatedRect) inView:view];
+ needsRepaint = ThemeMac::drawCellOrFocusRingWithViewIntoContext(toggleButtonCell, context, inflatedRect, view, true, isCellFocused, useImageBuffer, deviceScaleFactor);
#else
- [toggleButtonCell drawWithFrame:NSRect(inflatedRect) inView:view];
+ needsRepaint = ThemeMac::drawCellOrFocusRingWithViewIntoContext(toggleButtonCell, context, inflatedRect, view, true, isCellFocused, useImageBuffer, deviceScaleFactor);
#endif
- if (!isAnimating && (controlStates.states() & ControlStates::FocusState))
- needsRepaint = drawCellFocusRing(toggleButtonCell.get(), inflatedRect, view);
[toggleButtonCell setControlView:nil];
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
setUpButtonCell(cell, part, controlStates, zoomedSize, zoomFactor);
return cell;
}
-
-static float buttonFocusRectOutlineWidth()
-{
- return 3.0f;
-}
static void paintButton(ControlPart part, ControlStates& controlStates, GraphicsContext* context, const FloatRect& zoomedRect, float zoomFactor, ScrollView* scrollView, float deviceScaleFactor, float pageScaleFactor)
{
}
}
- bool shouldUseImageBuffer = pageScaleFactor != 1.0f || zoomFactor != 1.0f;
- float focusThickness = buttonFocusRectOutlineWidth();
-
- std::unique_ptr<ImageBuffer> imageBuffer;
- GraphicsContext* drawButtonContext = context;
- if (shouldUseImageBuffer) {
- imageBuffer = ImageBuffer::createCompatibleBuffer(inflatedRect.size() + 2 * FloatSize(focusThickness, focusThickness), deviceScaleFactor, ColorSpaceDeviceRGB, context, false);
- drawButtonContext = imageBuffer->context();
- }
- LocalCurrentGraphicsContext localContext(drawButtonContext);
+ LocalCurrentGraphicsContext localContext(context);
NSView *view = ThemeMac::ensuredView(scrollView, controlStates);
NSWindow *window = [view window];
NSButtonCell *previousDefaultButtonCell = [window defaultButtonCell];
+ bool useImageBuffer = pageScaleFactor != 1.0f || zoomFactor != 1.0f;
+ bool needsRepaint = ThemeMac::drawCellOrFocusRingWithViewIntoContext(buttonCell, context, inflatedRect, view, true, states & ControlStates::FocusState, useImageBuffer, deviceScaleFactor);
if (states & ControlStates::DefaultState) {
[window setDefaultButtonCell:buttonCell];
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101000
#endif
} else if ([previousDefaultButtonCell isEqual:buttonCell])
[window setDefaultButtonCell:nil];
-
- FloatRect drawFromImageBufferRect(focusThickness, focusThickness, inflatedRect.width(), inflatedRect.height());
- if (shouldUseImageBuffer) {
- [buttonCell drawWithFrame:NSRect(drawFromImageBufferRect) inView:view];
- if (!(states & ControlStates::FocusState))
- context->drawImageBuffer(imageBuffer.get(), ColorSpaceDeviceRGB, inflatedRect.location() - FloatSize(focusThickness, focusThickness));
- } else
- [buttonCell drawWithFrame:NSRect(inflatedRect) inView:view];
-
- if (states & ControlStates::FocusState) {
- if (shouldUseImageBuffer) {
- drawCellFocusRing(buttonCell, NSRect(drawFromImageBufferRect), view);
- context->drawImageBuffer(imageBuffer.get(), ColorSpaceDeviceRGB, inflatedRect.location() - FloatSize(focusThickness, focusThickness));
- } else
- drawCellFocusRing(buttonCell, NSRect(inflatedRect), view);
- }
- controlStates.setNeedsRepaint(false);
+ controlStates.setNeedsRepaint(needsRepaint);
[buttonCell setControlView:nil];
focusRingClipRect = rect;
}
+const float buttonFocusRectOutlineWidth = 3.0f;
+
+bool ThemeMac::drawCellOrFocusRingWithViewIntoContext(RetainPtr<NSCell> cell, GraphicsContext* context, const FloatRect& inflatedRect, NSView* view, bool drawButtonCell, bool drawFocusRing, bool useImageBuffer, float deviceScaleFactor)
+{
+ ASSERT(drawButtonCell || drawFocusRing);
+ bool needsRepaint = false;
+ if (useImageBuffer) {
+ NSRect imageBufferDrawRect = CGRectMake(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth, inflatedRect.width(), inflatedRect.height());
+ std::unique_ptr<ImageBuffer> imageBuffer = ImageBuffer::createCompatibleBuffer(inflatedRect.size() + 2 * FloatSize(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth), deviceScaleFactor, ColorSpaceSRGB, context, false);
+ {
+ LocalCurrentGraphicsContext localContext(imageBuffer->context());
+ if (drawButtonCell)
+ [cell drawWithFrame:imageBufferDrawRect inView:view];
+
+ if (drawFocusRing)
+ needsRepaint = drawCellFocusRing(cell.get(), imageBufferDrawRect, view);
+ }
+ context->drawImageBuffer(imageBuffer.get(), ColorSpaceSRGB, inflatedRect.location() - FloatSize(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth));
+ return needsRepaint;
+ }
+ if (drawButtonCell)
+ [cell drawWithFrame:NSRect(inflatedRect) inView:view];
+
+ if (drawFocusRing)
+ needsRepaint = drawCellFocusRing(cell.get(), NSRect(inflatedRect), view);
+
+ return needsRepaint;
+}
+
// Theme overrides
int ThemeMac::baselinePositionAdjustment(ControlPart part) const
{
switch (part) {
case CheckboxPart:
- paintToggleButton(part, states, context, zoomedRect, zoomFactor, scrollView);
+ paintToggleButton(part, states, context, zoomedRect, zoomFactor, scrollView, deviceScaleFactor, pageScaleFactor);
break;
case RadioPart:
- paintToggleButton(part, states, context, zoomedRect, zoomFactor, scrollView);
+ paintToggleButton(part, states, context, zoomedRect, zoomFactor, scrollView, deviceScaleFactor, pageScaleFactor);
break;
case PushButtonPart:
case DefaultButtonPart: