Title: [187961] trunk/Source/WebCore
Revision
187961
Author
wenson_hs...@apple.com
Date
2015-08-05 09:03:06 -0700 (Wed, 05 Aug 2015)

Log Message

Checkboxes and radio buttons should scale when zooming or pinching to zoom
https://bugs.webkit.org/show_bug.cgi?id=147405

Reviewed by Dean Jackson.

Refactors paintButton and paintToggleButton to use a temporary buffer when rendering
if the controls are zoomed. This affects checkboxes, radio buttons, and normal (push)
buttons.

* platform/mac/ThemeMac.h:
* platform/mac/ThemeMac.mm:
(WebCore::paintToggleButton): Refactored to use drawCellOrFocusRingWithViewIntoContext.
(WebCore::paintButton): Refactored to use drawCellOrFocusRingWithViewIntoContext.
(WebCore::ThemeMac::drawCellOrFocusRingWithViewIntoContext): Draws a given button cell
    and/or its focus ring into the given context, optionally using an offscreen buffer.
    This is a static function in ThemeMac so it can be accessed later on by
    RenderThemeMac when painting search fields that scale with zoom.
(WebCore::ThemeMac::paint):
(WebCore::buttonFocusRectOutlineWidth): Deleted. Made this value into a const float.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (187960 => 187961)


--- trunk/Source/WebCore/ChangeLog	2015-08-05 14:07:51 UTC (rev 187960)
+++ trunk/Source/WebCore/ChangeLog	2015-08-05 16:03:06 UTC (rev 187961)
@@ -1,3 +1,25 @@
+2015-08-04  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Checkboxes and radio buttons should scale when zooming or pinching to zoom
+        https://bugs.webkit.org/show_bug.cgi?id=147405
+
+        Reviewed by Dean Jackson.
+
+        Refactors paintButton and paintToggleButton to use a temporary buffer when rendering
+        if the controls are zoomed. This affects checkboxes, radio buttons, and normal (push)
+        buttons.
+
+        * platform/mac/ThemeMac.h:
+        * platform/mac/ThemeMac.mm:
+        (WebCore::paintToggleButton): Refactored to use drawCellOrFocusRingWithViewIntoContext.
+        (WebCore::paintButton): Refactored to use drawCellOrFocusRingWithViewIntoContext.
+        (WebCore::ThemeMac::drawCellOrFocusRingWithViewIntoContext): Draws a given button cell
+            and/or its focus ring into the given context, optionally using an offscreen buffer.
+            This is a static function in ThemeMac so it can be accessed later on by
+            RenderThemeMac when painting search fields that scale with zoom.
+        (WebCore::ThemeMac::paint):
+        (WebCore::buttonFocusRectOutlineWidth): Deleted. Made this value into a const float.
+
 2015-08-04  Doug Russell  <d_russ...@apple.com>
 
         AX: tree item children returned from ranged getter are different from full array of children

Modified: trunk/Source/WebCore/platform/mac/ThemeMac.h (187960 => 187961)


--- trunk/Source/WebCore/platform/mac/ThemeMac.h	2015-08-05 14:07:51 UTC (rev 187960)
+++ trunk/Source/WebCore/platform/mac/ThemeMac.h	2015-08-05 16:03:06 UTC (rev 187961)
@@ -58,6 +58,7 @@
     // FIXME: Once RenderThemeMac is converted over to use Theme then this can be internal to ThemeMac.
     static NSView* ensuredView(ScrollView*, const ControlStates&, bool useUnparentedView = false);
     static void setFocusRingClipRect(const FloatRect&);
+    static bool drawCellOrFocusRingWithViewIntoContext(RetainPtr<NSCell>, GraphicsContext*, const FloatRect&, NSView*, bool /* drawButtonCell */, bool /* drawFocusRing */, bool /* useImageBuffer */, float /* deviceScaleFactor */);
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/mac/ThemeMac.mm (187960 => 187961)


--- trunk/Source/WebCore/platform/mac/ThemeMac.mm	2015-08-05 14:07:51 UTC (rev 187960)
+++ trunk/Source/WebCore/platform/mac/ThemeMac.mm	2015-08-05 16:03:06 UTC (rev 187961)
@@ -376,7 +376,7 @@
     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
 
@@ -425,8 +425,9 @@
 #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]) {
@@ -435,15 +436,14 @@
         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
@@ -519,11 +519,6 @@
     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)
 {
@@ -558,21 +553,14 @@
         }
     }
     
-    bool shouldUseImageBuffer = pageScaleFactor != 1.0f || zoomFactor != 1.0f;
-    float focusThickness = buttonFocusRectOutlineWidth();
+    LocalCurrentGraphicsContext localContext(context);
     
-    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);
-    
     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
@@ -580,24 +568,8 @@
 #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];
 
@@ -690,6 +662,35 @@
     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
@@ -843,10 +844,10 @@
 {
     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:
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to