Title: [190623] trunk/Source/WebCore
Revision
190623
Author
wenson_hs...@apple.com
Date
2015-10-06 10:28:02 -0700 (Tue, 06 Oct 2015)

Log Message

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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (190622 => 190623)


--- trunk/Source/WebCore/ChangeLog	2015-10-06 17:21:22 UTC (rev 190622)
+++ trunk/Source/WebCore/ChangeLog	2015-10-06 17:28:02 UTC (rev 190623)
@@ -1,3 +1,23 @@
+2015-10-05  Wenson Hsieh  <wenson_hs...@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  <cdu...@apple.com>
 
         [Web IDL] 'length' property is wrong for variadic operations

Modified: trunk/Source/WebCore/platform/mac/ThemeMac.mm (190622 => 190623)


--- trunk/Source/WebCore/platform/mac/ThemeMac.mm	2015-10-06 17:21:22 UTC (rev 190622)
+++ trunk/Source/WebCore/platform/mac/ThemeMac.mm	2015-10-06 17:28:02 UTC (rev 190623)
@@ -664,30 +664,38 @@
 
 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];
+        needsRepaint = drawCellOrFocusRingIntoRectWithView(cell, NSRect(rect), view, drawButtonCell, drawFocusRing);
     
-    if (drawFocusRing)
-        needsRepaint = drawCellFocusRing(cell, NSRect(inflatedRect), view);
-    
     return needsRepaint;
 }
 

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (190622 => 190623)


--- trunk/Source/WebCore/rendering/RenderThemeMac.mm	2015-10-06 17:21:22 UTC (rev 190622)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm	2015-10-06 17:28:02 UTC (rev 190623)
@@ -1581,7 +1581,11 @@
         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;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to