Changeset 63514 in webkit


Ignore:
Timestamp:
Jul 15, 2010 9:55:03 PM (14 years ago)
Author:
tkent@chromium.org
Message:

2010-07-15 Kent Tamura <tkent@chromium.org>

Reviewed by Eric Seidel.

[Chromium] Update ThemeChromiumMac.mm for the recent changes of ThemeMac.mm
https://bugs.webkit.org/show_bug.cgi?id=41932

Sync with ThemeMac.mm r61760.
This change doesn't contain r54299, r57603, r57734, r57741, and
r58533 because they conflict with Chromium change for
FlippedView().

  • platform/chromium/ThemeChromiumMac.mm: (WebCore::sizeFromNSControlSize): (WebCore::sizeFromFont): (WebCore::controlSizeFromPixelSize): (WebCore::setControlSize): (WebCore::convertControlStatesToThemeDrawState): (WebCore::stepperSizes): (WebCore::stepperControlSizeForFont): (WebCore::paintStepper): (WebCore::ThemeChromiumMac::controlSize): (WebCore::ThemeChromiumMac::minimumControlSize): (WebCore::ThemeChromiumMac::inflateControlPaintRect): (WebCore::ThemeChromiumMac::paint):
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r63511 r63514  
     12010-07-15  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        [Chromium] Update ThemeChromiumMac.mm for the recent changes of ThemeMac.mm
     6        https://bugs.webkit.org/show_bug.cgi?id=41932
     7
     8        Sync with ThemeMac.mm r61760.
     9        This change doesn't contain r54299, r57603, r57734, r57741, and
     10        r58533 because they conflict with Chromium change for
     11        FlippedView().
     12
     13        * platform/chromium/ThemeChromiumMac.mm:
     14        (WebCore::sizeFromNSControlSize):
     15        (WebCore::sizeFromFont):
     16        (WebCore::controlSizeFromPixelSize):
     17        (WebCore::setControlSize):
     18        (WebCore::convertControlStatesToThemeDrawState):
     19        (WebCore::stepperSizes):
     20        (WebCore::stepperControlSizeForFont):
     21        (WebCore::paintStepper):
     22        (WebCore::ThemeChromiumMac::controlSize):
     23        (WebCore::ThemeChromiumMac::minimumControlSize):
     24        (WebCore::ThemeChromiumMac::inflateControlPaintRect):
     25        (WebCore::ThemeChromiumMac::paint):
     26
    1272010-07-15  MORITA Hajime  <morrita@google.com>
    228
  • trunk/WebCore/platform/chromium/ThemeChromiumMac.mm

    r61486 r63514  
    3333#import "ScrollView.h"
    3434#import "WebCoreSystemInterface.h"
     35#import <Carbon/Carbon.h>
    3536#include <wtf/StdLibExtras.h>
    3637#import <objc/runtime.h>
     
    211212}
    212213
    213 static LengthSize sizeFromFont(const Font& font, const LengthSize& zoomedSize, float zoomFactor, const IntSize* sizes)
    214 {
    215     IntSize controlSize = sizes[controlSizeForFont(font)];
     214static LengthSize sizeFromNSControlSize(NSControlSize nsControlSize, const LengthSize& zoomedSize, float zoomFactor, const IntSize* sizes)
     215{
     216    IntSize controlSize = sizes[nsControlSize];
    216217    if (zoomFactor != 1.0f)
    217218        controlSize = IntSize(controlSize.width() * zoomFactor, controlSize.height() * zoomFactor);
     
    224225}
    225226
    226 static void setControlSize(NSCell* cell, const IntSize* sizes, const IntSize& minZoomedSize, float zoomFactor)
    227 {
    228     NSControlSize size;
     227static LengthSize sizeFromFont(const Font& font, const LengthSize& zoomedSize, float zoomFactor, const IntSize* sizes)
     228{
     229    return sizeFromNSControlSize(controlSizeForFont(font), zoomedSize, zoomFactor, sizes);
     230}
     231
     232static ControlSize controlSizeFromPixelSize(const IntSize* sizes, const IntSize& minZoomedSize, float zoomFactor)
     233{
    229234    if (minZoomedSize.width() >= static_cast<int>(sizes[NSRegularControlSize].width() * zoomFactor) &&
    230235        minZoomedSize.height() >= static_cast<int>(sizes[NSRegularControlSize].height() * zoomFactor))
    231         size = NSRegularControlSize;
    232     else if (minZoomedSize.width() >= static_cast<int>(sizes[NSSmallControlSize].width() * zoomFactor) &&
    233              minZoomedSize.height() >= static_cast<int>(sizes[NSSmallControlSize].height() * zoomFactor))
    234         size = NSSmallControlSize;
    235     else
    236         size = NSMiniControlSize;
     236        return NSRegularControlSize;
     237    if (minZoomedSize.width() >= static_cast<int>(sizes[NSSmallControlSize].width() * zoomFactor) &&
     238        minZoomedSize.height() >= static_cast<int>(sizes[NSSmallControlSize].height() * zoomFactor))
     239        return NSSmallControlSize;
     240    return NSMiniControlSize;
     241}
     242
     243static void setControlSize(NSCell* cell, const IntSize* sizes, const IntSize& minZoomedSize, float zoomFactor)
     244{
     245    ControlSize size = controlSizeFromPixelSize(sizes, minZoomedSize, zoomFactor);
    237246    if (size != [cell controlSize]) // Only update if we have to, since AppKit does work even if the size is the same.
    238         [cell setControlSize:size];
     247        [cell setControlSize:(NSControlSize)size];
    239248}
    240249
     
    276285    if (tint != oldTint)
    277286        [cell setControlTint:tint];
     287}
     288
     289static ThemeDrawState convertControlStatesToThemeDrawState(ThemeButtonKind kind, ControlStates states)
     290{
     291    if (states & ReadOnlyState)
     292        return kThemeStateUnavailableInactive;
     293    if (!(states & EnabledState))
     294        return kThemeStateUnavailableInactive;
     295
     296    // Do not process PressedState if !EnabledState or ReadOnlyState.
     297    if (states & PressedState) {
     298        if (kind == kThemeIncDecButton || kind == kThemeIncDecButtonSmall || kind == kThemeIncDecButtonMini)
     299            return states & SpinUpState ? kThemeStatePressedUp : kThemeStatePressedDown;
     300        return kThemeStatePressed;
     301    }
     302    return kThemeStateActive;
    278303}
    279304
     
    572597}
    573598
     599// Stepper
     600
     601static const IntSize* stepperSizes()
     602{
     603    static const IntSize sizes[3] = { IntSize(19, 27), IntSize(15, 22), IntSize(13, 15) };
     604    return sizes;
     605}
     606
     607// We don't use controlSizeForFont() for steppers because the stepper height
     608// should be equal to or less than the corresponding text field height,
     609static NSControlSize stepperControlSizeForFont(const Font& font)
     610{
     611    int fontSize = font.pixelSize();
     612    if (fontSize >= 18)
     613        return NSRegularControlSize;
     614    if (fontSize >= 13)
     615        return NSSmallControlSize;
     616    return NSMiniControlSize;
     617}
     618
     619static void paintStepper(ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollView*)
     620{
     621    // We don't use NSStepperCell because there are no ways to draw an
     622    // NSStepperCell with the up button highlighted.
     623
     624    HIThemeButtonDrawInfo drawInfo;
     625    drawInfo.version = 0;
     626    drawInfo.state = convertControlStatesToThemeDrawState(kThemeIncDecButton, states);
     627    drawInfo.adornment = kThemeAdornmentDefault;
     628    ControlSize controlSize = controlSizeFromPixelSize(stepperSizes(), zoomedRect.size(), zoomFactor);
     629    if (controlSize == NSSmallControlSize)
     630        drawInfo.kind = kThemeIncDecButtonSmall;
     631    else if (controlSize == NSMiniControlSize)
     632        drawInfo.kind = kThemeIncDecButtonMini;
     633    else
     634        drawInfo.kind = kThemeIncDecButton;
     635
     636    IntRect rect(zoomedRect);
     637    context->save();
     638    if (zoomFactor != 1.0f) {
     639        rect.setWidth(rect.width() / zoomFactor);
     640        rect.setHeight(rect.height() / zoomFactor);
     641        context->translate(rect.x(), rect.y());
     642        context->scale(FloatSize(zoomFactor, zoomFactor));
     643        context->translate(-rect.x(), -rect.y());
     644    }
     645    CGRect bounds(rect);
     646    // Adjust 'bounds' so that HIThemeDrawButton(bounds,...) draws exactly on 'rect'.
     647    CGRect backgroundBounds;
     648    HIThemeGetButtonBackgroundBounds(&bounds, &drawInfo, &backgroundBounds);
     649    if (bounds.origin.x != backgroundBounds.origin.x)
     650        bounds.origin.x += bounds.origin.x - backgroundBounds.origin.x;
     651    if (bounds.origin.y != backgroundBounds.origin.y)
     652        bounds.origin.y += bounds.origin.y - backgroundBounds.origin.y;
     653    HIThemeDrawButton(&bounds, &drawInfo, context->platformContext(), kHIThemeOrientationNormal, 0);
     654    context->restore();
     655}
     656
    574657// Theme overrides
    575658
     
    614697            return sizeFromFont(font, LengthSize(zoomedSize.width(), Length()), zoomFactor, listButtonSizes());
    615698#endif
     699        case InnerSpinButtonPart:
     700            // We don't use inner spin buttons on Mac.
     701            return LengthSize(Length(Fixed), Length(Fixed));
     702        case OuterSpinButtonPart:
     703            if (!zoomedSize.width().isIntrinsicOrAuto() && !zoomedSize.height().isIntrinsicOrAuto())
     704                return zoomedSize;
     705            return sizeFromNSControlSize(stepperControlSizeForFont(font), zoomedSize, zoomFactor, stepperSizes());
    616706        default:
    617707            return zoomedSize;
     
    627717        case ListButtonPart:
    628718            return LengthSize(Length(0, Fixed), Length(static_cast<int>(15 * zoomFactor), Fixed));
     719        case InnerSpinButtonPart:
     720            // We don't use inner spin buttons on Mac.
     721            return LengthSize(Length(Fixed), Length(Fixed));
     722        case OuterSpinButtonPart: {
     723            IntSize base = stepperSizes()[NSMiniControlSize];
     724            return LengthSize(Length(static_cast<int>(base.width() * zoomFactor), Fixed),
     725                              Length(static_cast<int>(base.height() * zoomFactor), Fixed));
     726        }
    629727        default:
    630728            return Theme::minimumControlSize(part, font, zoomFactor);
     
    703801            break;
    704802        }
     803        case OuterSpinButtonPart: {
     804            static const int stepperMargin[4] = { 0, 0, 0, 0};
     805            ControlSize controlSize = controlSizeFromPixelSize(stepperSizes(), zoomedRect.size(), zoomFactor);
     806            IntSize zoomedSize = stepperSizes()[controlSize];
     807            zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
     808            zoomedSize.setWidth(zoomedSize.width() * zoomFactor);
     809            zoomedRect = inflateRect(zoomedRect, zoomedSize, stepperMargin, zoomFactor);
     810            break;
     811        }
    705812        default:
    706813            break;
     
    725832            paintButton(part, states, context, zoomedRect, zoomFactor, scrollView);
    726833            break;
     834        case OuterSpinButtonPart:
     835            paintStepper(states, context, zoomedRect, zoomFactor, scrollView);
     836            break;
    727837        default:
    728838            break;
Note: See TracChangeset for help on using the changeset viewer.