Slider knobs should scale when rendering while zoomed
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Oct 2015 17:28:02 +0000 (17:28 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Oct 2015 17:28:02 +0000 (17:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=149835
<rdar://problem/22897080>

Reviewed by Darin Adler.

Make slider knobs follow suit with the rest of the unscaled form controls
by rendering to an offscreen buffer when the page is zoomed or scaled and
then rendering a scaled version of the offscreen buffer onto the page.

* platform/mac/ThemeMac.mm:
(WebCore::drawCellOrFocusRingIntoRectWithView): Helper function for drawing
    cells and/or focus rings.
(WebCore::ThemeMac::drawCellOrFocusRingWithViewIntoContext): Refactored to
    handle drawing slider knobs as well.
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::paintSliderThumb): Use scaled rendering when necessary.

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

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

index ca73def6a95be71adc15f96d3f41c28be4d00804..33084222b4ae4ca3274c4b77e9d6cbcdc9267fce 100644 (file)
@@ -1,3 +1,23 @@
+2015-10-05  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Slider knobs should scale when rendering while zoomed
+        https://bugs.webkit.org/show_bug.cgi?id=149835
+        <rdar://problem/22897080>
+
+        Reviewed by Darin Adler.
+
+        Make slider knobs follow suit with the rest of the unscaled form controls
+        by rendering to an offscreen buffer when the page is zoomed or scaled and
+        then rendering a scaled version of the offscreen buffer onto the page.
+
+        * platform/mac/ThemeMac.mm:
+        (WebCore::drawCellOrFocusRingIntoRectWithView): Helper function for drawing
+            cells and/or focus rings.
+        (WebCore::ThemeMac::drawCellOrFocusRingWithViewIntoContext): Refactored to
+            handle drawing slider knobs as well.
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::paintSliderThumb): Use scaled rendering when necessary.
+
 2015-10-06  Chris Dumez  <cdumez@apple.com>
 
         [Web IDL] 'length' property is wrong for variadic operations
index 9d4626ade61442342a7d3fb0f98c132bce5762d8..ff29a1decd8b720d44b142309aacce3bbeeda18f 100644 (file)
@@ -664,29 +664,37 @@ void ThemeMac::setFocusRingClipRect(const FloatRect& rect)
 
 const float buttonFocusRectOutlineWidth = 3.0f;
 
-bool ThemeMac::drawCellOrFocusRingWithViewIntoContext(NSCell* cell, GraphicsContext& context, const FloatRect& inflatedRect, NSView* view, bool drawButtonCell, bool drawFocusRing, bool useImageBuffer, float deviceScaleFactor)
+static inline bool drawCellOrFocusRingIntoRectWithView(NSCell *cell, NSRect rect, NSView *view, bool drawButtonCell, bool drawFocusRing)
+{
+    if (drawButtonCell) {
+        if ([cell isKindOfClass:[NSSliderCell class]]) {
+            // For slider cells, draw only the knob.
+            [(NSSliderCell *)cell drawKnob:rect];
+        } else
+            [cell drawWithFrame:rect inView:view];
+    }
+    if (drawFocusRing)
+        return drawCellFocusRing(cell, rect, view);
+
+    return false;
+}
+
+bool ThemeMac::drawCellOrFocusRingWithViewIntoContext(NSCell *cell, GraphicsContext& context, const FloatRect& rect, NSView *view, bool drawButtonCell, bool drawFocusRing, bool useImageBuffer, float deviceScaleFactor)
 {
     ASSERT(drawButtonCell || drawFocusRing);
     bool needsRepaint = false;
     if (useImageBuffer) {
-        NSRect imageBufferDrawRect = NSRect(FloatRect(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth, inflatedRect.width(), inflatedRect.height()));
-        std::unique_ptr<ImageBuffer> imageBuffer = ImageBuffer::createCompatibleBuffer(inflatedRect.size() + 2 * FloatSize(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth), deviceScaleFactor, ColorSpaceSRGB, context, false);
+        NSRect imageBufferDrawRect = NSRect(FloatRect(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth, rect.width(), rect.height()));
+        auto imageBuffer = ImageBuffer::createCompatibleBuffer(rect.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, imageBufferDrawRect, view);
+            needsRepaint = drawCellOrFocusRingIntoRectWithView(cell, imageBufferDrawRect, view, drawButtonCell, drawFocusRing);
         }
-        context.drawImageBuffer(imageBuffer.get(), ColorSpaceSRGB, inflatedRect.location() - FloatSize(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth));
+        context.drawImageBuffer(imageBuffer.get(), ColorSpaceSRGB, rect.location() - FloatSize(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth));
         return needsRepaint;
     }
     if (drawButtonCell)
-        [cell drawWithFrame:NSRect(inflatedRect) inView:view];
-    
-    if (drawFocusRing)
-        needsRepaint = drawCellFocusRing(cell, NSRect(inflatedRect), view);
+        needsRepaint = drawCellOrFocusRingIntoRectWithView(cell, NSRect(rect), view, drawButtonCell, drawFocusRing);
     
     return needsRepaint;
 }
index edb33e647fbfa29e9a9fbaea323c8bbced08c755..496764599000456719f6be2dd2c88799ae348ca9 100644 (file)
@@ -1581,7 +1581,11 @@ bool RenderThemeMac::paintSliderThumb(const RenderObject& o, const PaintInfo& pa
         paintInfo.context().translate(-unzoomedRect.x(), -unzoomedRect.y());
     }
 
-    [sliderThumbCell drawKnob:unzoomedRect];
+    bool shouldDrawCell = true;
+    bool shouldDrawFocusRing = false;
+    float deviceScaleFactor = o.document().page()->deviceScaleFactor();
+    bool shouldUseImageBuffer = deviceScaleFactor != 1 || zoomLevel != 1;
+    ThemeMac::drawCellOrFocusRingWithViewIntoContext(sliderThumbCell, paintInfo.context(), unzoomedRect, view, shouldDrawCell, shouldDrawFocusRing, shouldUseImageBuffer, deviceScaleFactor);
     [sliderThumbCell setControlView:nil];
 
     return false;