Changeset 187961 in webkit


Ignore:
Timestamp:
Aug 5, 2015 9:03:06 AM (9 years ago)
Author:
Wenson Hsieh
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.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r187935 r187961  
     12015-08-04  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Checkboxes and radio buttons should scale when zooming or pinching to zoom
     4        https://bugs.webkit.org/show_bug.cgi?id=147405
     5
     6        Reviewed by Dean Jackson.
     7
     8        Refactors paintButton and paintToggleButton to use a temporary buffer when rendering
     9        if the controls are zoomed. This affects checkboxes, radio buttons, and normal (push)
     10        buttons.
     11
     12        * platform/mac/ThemeMac.h:
     13        * platform/mac/ThemeMac.mm:
     14        (WebCore::paintToggleButton): Refactored to use drawCellOrFocusRingWithViewIntoContext.
     15        (WebCore::paintButton): Refactored to use drawCellOrFocusRingWithViewIntoContext.
     16        (WebCore::ThemeMac::drawCellOrFocusRingWithViewIntoContext): Draws a given button cell
     17            and/or its focus ring into the given context, optionally using an offscreen buffer.
     18            This is a static function in ThemeMac so it can be accessed later on by
     19            RenderThemeMac when painting search fields that scale with zoom.
     20        (WebCore::ThemeMac::paint):
     21        (WebCore::buttonFocusRectOutlineWidth): Deleted. Made this value into a const float.
     22
    1232015-08-04  Doug Russell  <d_russell@apple.com>
    224
  • trunk/Source/WebCore/platform/mac/ThemeMac.h

    r187741 r187961  
    5959    static NSView* ensuredView(ScrollView*, const ControlStates&, bool useUnparentedView = false);
    6060    static void setFocusRingClipRect(const FloatRect&);
     61    static bool drawCellOrFocusRingWithViewIntoContext(RetainPtr<NSCell>, GraphicsContext*, const FloatRect&, NSView*, bool /* drawButtonCell */, bool /* drawFocusRing */, bool /* useImageBuffer */, float /* deviceScaleFactor */);
    6162};
    6263
  • trunk/Source/WebCore/platform/mac/ThemeMac.mm

    r187741 r187961  
    377377}
    378378
    379 static void paintToggleButton(ControlPart buttonType, ControlStates& controlStates, GraphicsContext* context, const FloatRect& zoomedRect, float zoomFactor, ScrollView* scrollView)
     379static void paintToggleButton(ControlPart buttonType, ControlStates& controlStates, GraphicsContext* context, const FloatRect& zoomedRect, float zoomFactor, ScrollView* scrollView, float deviceScaleFactor, float pageScaleFactor)
    380380{
    381381    BEGIN_BLOCK_OBJC_EXCEPTIONS
     
    426426    NSView *view = ThemeMac::ensuredView(scrollView, controlStates, useUnparentedView);
    427427
    428     bool isAnimating = false;
    429428    bool needsRepaint = false;
     429    bool useImageBuffer = pageScaleFactor != 1.0f || zoomFactor != 1.0f;
     430    bool isCellFocused = controlStates.states() & ControlStates::FocusState;
    430431
    431432#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
     
    436437
    437438        [toggleButtonCell _renderCurrentAnimationFrameInContext:context->platformContext() atLocation:NSMakePoint(0, 0)];
    438         isAnimating = [toggleButtonCell _stateAnimationRunning];
     439        if (![toggleButtonCell _stateAnimationRunning] && isCellFocused)
     440            needsRepaint = ThemeMac::drawCellOrFocusRingWithViewIntoContext(toggleButtonCell, context, inflatedRect, view, false, true, useImageBuffer, deviceScaleFactor);
    439441    } else
    440         [toggleButtonCell drawWithFrame:NSRect(inflatedRect) inView:view];
     442        needsRepaint = ThemeMac::drawCellOrFocusRingWithViewIntoContext(toggleButtonCell, context, inflatedRect, view, true, isCellFocused, useImageBuffer, deviceScaleFactor);
    441443#else
    442     [toggleButtonCell drawWithFrame:NSRect(inflatedRect) inView:view];
     444    needsRepaint = ThemeMac::drawCellOrFocusRingWithViewIntoContext(toggleButtonCell, context, inflatedRect, view, true, isCellFocused, useImageBuffer, deviceScaleFactor);
    443445#endif
    444446
    445     if (!isAnimating && (controlStates.states() & ControlStates::FocusState))
    446         needsRepaint = drawCellFocusRing(toggleButtonCell.get(), inflatedRect, view);
    447447    [toggleButtonCell setControlView:nil];
    448448
     
    519519    setUpButtonCell(cell, part, controlStates, zoomedSize, zoomFactor);
    520520    return cell;
    521 }
    522 
    523 static float buttonFocusRectOutlineWidth()
    524 {
    525     return 3.0f;
    526521}
    527522   
     
    559554    }
    560555   
    561     bool shouldUseImageBuffer = pageScaleFactor != 1.0f || zoomFactor != 1.0f;
    562     float focusThickness = buttonFocusRectOutlineWidth();
    563    
    564     std::unique_ptr<ImageBuffer> imageBuffer;
    565     GraphicsContext* drawButtonContext = context;
    566     if (shouldUseImageBuffer) {
    567         imageBuffer = ImageBuffer::createCompatibleBuffer(inflatedRect.size() + 2 * FloatSize(focusThickness, focusThickness), deviceScaleFactor, ColorSpaceDeviceRGB, context, false);
    568         drawButtonContext = imageBuffer->context();
    569     }
    570     LocalCurrentGraphicsContext localContext(drawButtonContext);
     556    LocalCurrentGraphicsContext localContext(context);
    571557   
    572558    NSView *view = ThemeMac::ensuredView(scrollView, controlStates);
     
    574560    NSButtonCell *previousDefaultButtonCell = [window defaultButtonCell];
    575561
     562    bool useImageBuffer = pageScaleFactor != 1.0f || zoomFactor != 1.0f;
     563    bool needsRepaint = ThemeMac::drawCellOrFocusRingWithViewIntoContext(buttonCell, context, inflatedRect, view, true, states & ControlStates::FocusState, useImageBuffer, deviceScaleFactor);
    576564    if (states & ControlStates::DefaultState) {
    577565        [window setDefaultButtonCell:buttonCell];
     
    581569    } else if ([previousDefaultButtonCell isEqual:buttonCell])
    582570        [window setDefaultButtonCell:nil];
    583 
    584     FloatRect drawFromImageBufferRect(focusThickness, focusThickness, inflatedRect.width(), inflatedRect.height());
    585     if (shouldUseImageBuffer) {
    586         [buttonCell drawWithFrame:NSRect(drawFromImageBufferRect) inView:view];
    587         if (!(states & ControlStates::FocusState))
    588             context->drawImageBuffer(imageBuffer.get(), ColorSpaceDeviceRGB, inflatedRect.location() - FloatSize(focusThickness, focusThickness));
    589     } else
    590         [buttonCell drawWithFrame:NSRect(inflatedRect) inView:view];
    591    
    592     if (states & ControlStates::FocusState) {
    593         if (shouldUseImageBuffer) {
    594             drawCellFocusRing(buttonCell, NSRect(drawFromImageBufferRect), view);
    595             context->drawImageBuffer(imageBuffer.get(), ColorSpaceDeviceRGB, inflatedRect.location() - FloatSize(focusThickness, focusThickness));
    596         } else
    597             drawCellFocusRing(buttonCell, NSRect(inflatedRect), view);
    598     }
    599    
    600     controlStates.setNeedsRepaint(false);
     571   
     572    controlStates.setNeedsRepaint(needsRepaint);
    601573
    602574    [buttonCell setControlView:nil];
     
    689661{
    690662    focusRingClipRect = rect;
     663}
     664
     665const float buttonFocusRectOutlineWidth = 3.0f;
     666
     667bool ThemeMac::drawCellOrFocusRingWithViewIntoContext(RetainPtr<NSCell> cell, GraphicsContext* context, const FloatRect& inflatedRect, NSView* view, bool drawButtonCell, bool drawFocusRing, bool useImageBuffer, float deviceScaleFactor)
     668{
     669    ASSERT(drawButtonCell || drawFocusRing);
     670    bool needsRepaint = false;
     671    if (useImageBuffer) {
     672        NSRect imageBufferDrawRect = CGRectMake(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth, inflatedRect.width(), inflatedRect.height());
     673        std::unique_ptr<ImageBuffer> imageBuffer = ImageBuffer::createCompatibleBuffer(inflatedRect.size() + 2 * FloatSize(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth), deviceScaleFactor, ColorSpaceSRGB, context, false);
     674        {
     675            LocalCurrentGraphicsContext localContext(imageBuffer->context());
     676            if (drawButtonCell)
     677                [cell drawWithFrame:imageBufferDrawRect inView:view];
     678           
     679            if (drawFocusRing)
     680                needsRepaint = drawCellFocusRing(cell.get(), imageBufferDrawRect, view);
     681        }
     682        context->drawImageBuffer(imageBuffer.get(), ColorSpaceSRGB, inflatedRect.location() - FloatSize(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth));
     683        return needsRepaint;
     684    }
     685    if (drawButtonCell)
     686        [cell drawWithFrame:NSRect(inflatedRect) inView:view];
     687   
     688    if (drawFocusRing)
     689        needsRepaint = drawCellFocusRing(cell.get(), NSRect(inflatedRect), view);
     690   
     691    return needsRepaint;
    691692}
    692693
     
    844845    switch (part) {
    845846        case CheckboxPart:
    846             paintToggleButton(part, states, context, zoomedRect, zoomFactor, scrollView);
     847            paintToggleButton(part, states, context, zoomedRect, zoomFactor, scrollView, deviceScaleFactor, pageScaleFactor);
    847848            break;
    848849        case RadioPart:
    849             paintToggleButton(part, states, context, zoomedRect, zoomFactor, scrollView);
     850            paintToggleButton(part, states, context, zoomedRect, zoomFactor, scrollView, deviceScaleFactor, pageScaleFactor);
    850851            break;
    851852        case PushButtonPart:
Note: See TracChangeset for help on using the changeset viewer.