Changeset 190623 in webkit


Ignore:
Timestamp:
Oct 6, 2015 10:28:02 AM (9 years ago)
Author:
Wenson Hsieh
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.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r190621 r190623  
     12015-10-05  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Slider knobs should scale when rendering while zoomed
     4        https://bugs.webkit.org/show_bug.cgi?id=149835
     5        <rdar://problem/22897080>
     6
     7        Reviewed by Darin Adler.
     8
     9        Make slider knobs follow suit with the rest of the unscaled form controls
     10        by rendering to an offscreen buffer when the page is zoomed or scaled and
     11        then rendering a scaled version of the offscreen buffer onto the page.
     12
     13        * platform/mac/ThemeMac.mm:
     14        (WebCore::drawCellOrFocusRingIntoRectWithView): Helper function for drawing
     15            cells and/or focus rings.
     16        (WebCore::ThemeMac::drawCellOrFocusRingWithViewIntoContext): Refactored to
     17            handle drawing slider knobs as well.
     18        * rendering/RenderThemeMac.mm:
     19        (WebCore::RenderThemeMac::paintSliderThumb): Use scaled rendering when necessary.
     20
    1212015-10-06  Chris Dumez  <cdumez@apple.com>
    222
  • trunk/Source/WebCore/platform/mac/ThemeMac.mm

    r189830 r190623  
    665665const float buttonFocusRectOutlineWidth = 3.0f;
    666666
    667 bool ThemeMac::drawCellOrFocusRingWithViewIntoContext(NSCell* cell, GraphicsContext& context, const FloatRect& inflatedRect, NSView* view, bool drawButtonCell, bool drawFocusRing, bool useImageBuffer, float deviceScaleFactor)
     667static inline bool drawCellOrFocusRingIntoRectWithView(NSCell *cell, NSRect rect, NSView *view, bool drawButtonCell, bool drawFocusRing)
     668{
     669    if (drawButtonCell) {
     670        if ([cell isKindOfClass:[NSSliderCell class]]) {
     671            // For slider cells, draw only the knob.
     672            [(NSSliderCell *)cell drawKnob:rect];
     673        } else
     674            [cell drawWithFrame:rect inView:view];
     675    }
     676    if (drawFocusRing)
     677        return drawCellFocusRing(cell, rect, view);
     678
     679    return false;
     680}
     681
     682bool ThemeMac::drawCellOrFocusRingWithViewIntoContext(NSCell *cell, GraphicsContext& context, const FloatRect& rect, NSView *view, bool drawButtonCell, bool drawFocusRing, bool useImageBuffer, float deviceScaleFactor)
    668683{
    669684    ASSERT(drawButtonCell || drawFocusRing);
    670685    bool needsRepaint = false;
    671686    if (useImageBuffer) {
    672         NSRect imageBufferDrawRect = NSRect(FloatRect(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth, inflatedRect.width(), inflatedRect.height()));
    673         std::unique_ptr<ImageBuffer> imageBuffer = ImageBuffer::createCompatibleBuffer(inflatedRect.size() + 2 * FloatSize(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth), deviceScaleFactor, ColorSpaceSRGB, context, false);
     687        NSRect imageBufferDrawRect = NSRect(FloatRect(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth, rect.width(), rect.height()));
     688        auto imageBuffer = ImageBuffer::createCompatibleBuffer(rect.size() + 2 * FloatSize(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth), deviceScaleFactor, ColorSpaceSRGB, context, false);
    674689        {
    675690            LocalCurrentGraphicsContext localContext(imageBuffer->context());
    676             if (drawButtonCell)
    677                 [cell drawWithFrame:imageBufferDrawRect inView:view];
    678            
    679             if (drawFocusRing)
    680                 needsRepaint = drawCellFocusRing(cell, imageBufferDrawRect, view);
    681         }
    682         context.drawImageBuffer(imageBuffer.get(), ColorSpaceSRGB, inflatedRect.location() - FloatSize(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth));
     691            needsRepaint = drawCellOrFocusRingIntoRectWithView(cell, imageBufferDrawRect, view, drawButtonCell, drawFocusRing);
     692        }
     693        context.drawImageBuffer(imageBuffer.get(), ColorSpaceSRGB, rect.location() - FloatSize(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth));
    683694        return needsRepaint;
    684695    }
    685696    if (drawButtonCell)
    686         [cell drawWithFrame:NSRect(inflatedRect) inView:view];
    687    
    688     if (drawFocusRing)
    689         needsRepaint = drawCellFocusRing(cell, NSRect(inflatedRect), view);
     697        needsRepaint = drawCellOrFocusRingIntoRectWithView(cell, NSRect(rect), view, drawButtonCell, drawFocusRing);
    690698   
    691699    return needsRepaint;
  • trunk/Source/WebCore/rendering/RenderThemeMac.mm

    r189830 r190623  
    15821582    }
    15831583
    1584     [sliderThumbCell drawKnob:unzoomedRect];
     1584    bool shouldDrawCell = true;
     1585    bool shouldDrawFocusRing = false;
     1586    float deviceScaleFactor = o.document().page()->deviceScaleFactor();
     1587    bool shouldUseImageBuffer = deviceScaleFactor != 1 || zoomLevel != 1;
     1588    ThemeMac::drawCellOrFocusRingWithViewIntoContext(sliderThumbCell, paintInfo.context(), unzoomedRect, view, shouldDrawCell, shouldDrawFocusRing, shouldUseImageBuffer, deviceScaleFactor);
    15851589    [sliderThumbCell setControlView:nil];
    15861590
Note: See TracChangeset for help on using the changeset viewer.