Changeset 61751 in webkit


Ignore:
Timestamp:
Jun 24, 2010 3:07:53 AM (14 years ago)
Author:
tkent@chromium.org
Message:

[Mac] The upper button of <input type=number> has no visual effect on click
https://bugs.webkit.org/show_bug.cgi?id=38380

Reviewed by Adam Barth.

WebCore:

Because we have no ways to draw an NSStepperCell with its up button
highlighted, use HIThemeDrawButton() instead.

Test: platform/mac/fast/forms/input-appearance-spinbutton-up.html

  • platform/mac/ThemeMac.mm:

(WebCore::controlSizeFromPixelSize):

New function. Made from a part of setControlSize().

(WebCore::setControlSize):
(WebCore::convertControlStatesToThemeDrawState):
(WebCore::paintStepper): Use HITheme API instead of NSStepperCell.
(WebCore::ThemeMac::inflateControlPaintRect):

Use controlSizeFromPixelSize().

LayoutTests:

  • platform/mac/fast/forms/input-appearance-spinbutton-expected.checksum:
  • platform/mac/fast/forms/input-appearance-spinbutton-expected.png:
  • platform/mac/fast/forms/input-appearance-spinbutton-up-expected.checksum: Added.
  • platform/mac/fast/forms/input-appearance-spinbutton-up-expected.png: Added.
  • platform/mac/fast/forms/input-appearance-spinbutton-up-expected.txt: Added.
  • platform/mac/fast/forms/input-appearance-spinbutton-up.html: Added.
Location:
trunk
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r61750 r61751  
     12010-06-24  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        [Mac] The upper button of <input type=number> has no visual effect on click
     6        https://bugs.webkit.org/show_bug.cgi?id=38380
     7
     8        * platform/mac/fast/forms/input-appearance-spinbutton-expected.checksum:
     9        * platform/mac/fast/forms/input-appearance-spinbutton-expected.png:
     10        * platform/mac/fast/forms/input-appearance-spinbutton-up-expected.checksum: Added.
     11        * platform/mac/fast/forms/input-appearance-spinbutton-up-expected.png: Added.
     12        * platform/mac/fast/forms/input-appearance-spinbutton-up-expected.txt: Added.
     13        * platform/mac/fast/forms/input-appearance-spinbutton-up.html: Added.
     14
    1152010-06-24  Oliver Hunt  <oliver@apple.com>
    216
  • trunk/LayoutTests/platform/mac/fast/forms/input-appearance-spinbutton-expected.checksum

    r58561 r61751  
    1 7ec81a98ab133c920958c45632320ba1
     1adc036c913c7b9c13a0fa71c28e22253
  • trunk/WebCore/ChangeLog

    r61749 r61751  
     12010-06-24  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        [Mac] The upper button of <input type=number> has no visual effect on click
     6        https://bugs.webkit.org/show_bug.cgi?id=38380
     7
     8        Because we have no ways to draw an NSStepperCell with its up button
     9        highlighted, use HIThemeDrawButton() instead.
     10
     11        Test: platform/mac/fast/forms/input-appearance-spinbutton-up.html
     12
     13        * platform/mac/ThemeMac.mm:
     14        (WebCore::controlSizeFromPixelSize):
     15          New function. Made from a part of setControlSize().
     16        (WebCore::setControlSize):
     17        (WebCore::convertControlStatesToThemeDrawState):
     18        (WebCore::paintStepper): Use HITheme API instead of NSStepperCell.
     19        (WebCore::ThemeMac::inflateControlPaintRect):
     20          Use controlSizeFromPixelSize().
     21
    1222010-06-24  Yury Semikhatsky  <yurys@chromium.org>
    223
  • trunk/WebCore/platform/mac/ThemeMac.mm

    r58561 r61751  
    3232#import "ScrollView.h"
    3333#import "WebCoreSystemInterface.h"
     34#import <Carbon/Carbon.h>
    3435#include <wtf/StdLibExtras.h>
    3536
     
    101102}
    102103
    103 static void setControlSize(NSCell* cell, const IntSize* sizes, const IntSize& minZoomedSize, float zoomFactor)
    104 {
    105     NSControlSize size;
     104static ControlSize controlSizeFromPixelSize(const IntSize* sizes, const IntSize& minZoomedSize, float zoomFactor)
     105{
    106106    if (minZoomedSize.width() >= static_cast<int>(sizes[NSRegularControlSize].width() * zoomFactor) &&
    107107        minZoomedSize.height() >= static_cast<int>(sizes[NSRegularControlSize].height() * zoomFactor))
    108         size = NSRegularControlSize;
    109     else if (minZoomedSize.width() >= static_cast<int>(sizes[NSSmallControlSize].width() * zoomFactor) &&
    110              minZoomedSize.height() >= static_cast<int>(sizes[NSSmallControlSize].height() * zoomFactor))
    111         size = NSSmallControlSize;
    112     else
    113         size = NSMiniControlSize;
     108        return NSRegularControlSize;
     109    if (minZoomedSize.width() >= static_cast<int>(sizes[NSSmallControlSize].width() * zoomFactor) &&
     110        minZoomedSize.height() >= static_cast<int>(sizes[NSSmallControlSize].height() * zoomFactor))
     111        return NSSmallControlSize;
     112    return NSMiniControlSize;
     113}
     114
     115static void setControlSize(NSCell* cell, const IntSize* sizes, const IntSize& minZoomedSize, float zoomFactor)
     116{
     117    NSControlSize size = controlSizeFromPixelSize(sizes, minZoomedSize, zoomFactor);
    114118    if (size != [cell controlSize]) // Only update if we have to, since AppKit does work even if the size is the same.
    115119        [cell setControlSize:size];
     
    148152    // Window inactive state does not need to be checked explicitly, since we paint parented to
    149153    // a view in a window whose key state can be detected.
     154}
     155
     156static ThemeDrawState convertControlStatesToThemeDrawState(ThemeButtonKind kind, ControlStates states)
     157{
     158    if (states & ReadOnlyState)
     159        return kThemeStateUnavailableInactive;
     160    if (!(states & EnabledState))
     161        return kThemeStateUnavailableInactive;
     162
     163    // Do not process PressedState if !EnabledState or ReadOnlyState.
     164    if (states & PressedState) {
     165        if (kind == kThemeIncDecButton || kind == kThemeIncDecButtonSmall || kind == kThemeIncDecButtonMini)
     166            return states & SpinUpState ? kThemeStatePressedUp : kThemeStatePressedDown;
     167        return kThemeStatePressed;
     168    }
     169    return kThemeStateActive;
    150170}
    151171
     
    470490}
    471491
    472 static NSStepperCell* stepper(ControlStates states, const IntRect& zoomedRect, float zoomFactor)
    473 {
    474     static NSStepperCell* cell = [[NSStepperCell alloc] init];
    475     setControlSize(cell, stepperSizes(), zoomedRect.size(), zoomFactor);
    476 
    477     updateStates(cell, states);
    478     if (states & PressedState && states & SpinUpState) {
    479         // FIXME: There is no way to draw a NSSteperCell with the up button hilighted.
    480         // Disables the hilight of the down button if the up button is pressed.
    481         [cell setHighlighted:NO];
    482     }
    483     return cell;
    484 }
    485 
    486 static void paintStepper(ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView)
    487 {
    488     NSStepperCell* cell = stepper(states, zoomedRect, zoomFactor);
    489 
     492static void paintStepper(ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollView*)
     493{
     494    // We don't use NSStepperCell because there are no ways to draw an
     495    // NSStepperCell with the up button highlighted.
     496
     497    HIThemeButtonDrawInfo drawInfo;
     498    drawInfo.version = 0;
     499    drawInfo.state = convertControlStatesToThemeDrawState(kThemeIncDecButton, states);
     500    drawInfo.adornment = kThemeAdornmentDefault;
     501    ControlSize controlSize = controlSizeFromPixelSize(stepperSizes(), zoomedRect.size(), zoomFactor);
     502    if (controlSize == NSSmallControlSize)
     503        drawInfo.kind = kThemeIncDecButtonSmall;
     504    else if (controlSize == NSMiniControlSize)
     505        drawInfo.kind = kThemeIncDecButtonMini;
     506    else
     507        drawInfo.kind = kThemeIncDecButton;
     508
     509    IntRect rect(zoomedRect);
    490510    context->save();
    491     NSControlSize controlSize = [cell controlSize];
    492     IntSize zoomedSize = stepperSizes()[controlSize];
    493     IntRect rect(zoomedRect);
    494 
    495511    if (zoomFactor != 1.0f) {
    496512        rect.setWidth(rect.width() / zoomFactor);
     
    500516        context->translate(-rect.x(), -rect.y());
    501517    }
    502 
    503     BEGIN_BLOCK_OBJC_EXCEPTIONS
    504     [cell drawWithFrame:NSRect(rect) inView:ThemeMac::ensuredView(scrollView)];
    505     [cell setControlView:nil];
    506     END_BLOCK_OBJC_EXCEPTIONS
    507 
     518    CGRect bounds(rect);
     519    // Adjust 'bounds' so that HIThemeDrawButton(bounds,...) draws exactly on 'rect'.
     520    CGRect backgroundBounds;
     521    HIThemeGetButtonBackgroundBounds(&bounds, &drawInfo, &backgroundBounds);
     522    if (bounds.origin.x != backgroundBounds.origin.x)
     523        bounds.origin.x += bounds.origin.x - backgroundBounds.origin.x;
     524    if (bounds.origin.y != backgroundBounds.origin.y)
     525        bounds.origin.y += bounds.origin.y - backgroundBounds.origin.y;
     526    HIThemeDrawButton(&bounds, &drawInfo, context->platformContext(), kHIThemeOrientationNormal, 0);
    508527    context->restore();
    509528}
     
    670689        case OuterSpinButtonPart: {
    671690            static const int stepperMargin[4] = { 0, 0, 0, 0};
    672             NSCell *cell = stepper(states, zoomedRect, zoomFactor);
    673             NSControlSize controlSize = [cell controlSize];
     691            NSControlSize controlSize = controlSizeFromPixelSize(stepperSizes(), zoomedRect.size(), zoomFactor);
    674692            IntSize zoomedSize = stepperSizes()[controlSize];
    675693            zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
Note: See TracChangeset for help on using the changeset viewer.