/* * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. * Copyright (C) 2008, 2009 Google, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ // FIXME: we still need to figure out if passing a null view to the cell // drawing routines will work. I expect not, and if that's the case we'll have // to figure out something else. For now, at least leave the lines commented // in, but the procurement of the view if 0'd. #import "config.h" #import "RenderThemeChromiumMac.h" #import #import #import #import "BitmapImage.h" #import "CSSStyleSelector.h" #import "CSSValueKeywords.h" #import "Document.h" #import "Element.h" #import "FoundationExtras.h" #import "FrameView.h" #import "GraphicsContext.h" #import "HTMLInputElement.h" #import "HTMLMediaElement.h" #import "HTMLNames.h" #import "Image.h" #import "LocalCurrentGraphicsContext.h" #import "MediaControlElements.h" #import "RenderSlider.h" #import "RenderView.h" #import "SharedBuffer.h" #import "WebCoreSystemInterface.h" #import #ifdef BUILDING_ON_TIGER typedef int NSInteger; typedef unsigned NSUInteger; #endif using std::min; // The methods in this file are specific to the Mac OS X platform. // FIXME: The platform-independent code in this class should be factored out and merged with RenderThemeSafari. @interface WebCoreRenderThemeNotificationObserver : NSObject { WebCore::RenderTheme *_theme; } - (id)initWithTheme:(WebCore::RenderTheme *)theme; - (void)systemColorsDidChange:(NSNotification *)notification; @end @implementation WebCoreRenderThemeNotificationObserver - (id)initWithTheme:(WebCore::RenderTheme *)theme { [super init]; _theme = theme; return self; } - (void)systemColorsDidChange:(NSNotification *)notification { ASSERT([[notification name] isEqualToString:NSSystemColorsDidChangeNotification]); _theme->platformColorsDidChange(); } @end namespace WebCore { using namespace HTMLNames; enum { TopMargin, RightMargin, BottomMargin, LeftMargin }; enum { TopPadding, RightPadding, BottomPadding, LeftPadding }; // In our Mac port, we don't define PLATFORM(MAC) and thus don't pick up the // |operator NSRect()| on WebCore::IntRect and FloatRect. This substitues for // that missing conversion operator. NSRect IntRectToNSRect(const IntRect & rect) { return NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height()); } NSRect FloatRectToNSRect(const FloatRect & rect) { return NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height()); } IntRect NSRectToIntRect(const NSRect & rect) { return IntRect(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); } RenderTheme* theme() { static RenderThemeChromiumMac* macTheme = new RenderThemeChromiumMac; return macTheme; } RenderThemeChromiumMac::RenderThemeChromiumMac() : m_isSliderThumbHorizontalPressed(false) , m_isSliderThumbVerticalPressed(false) , m_notificationObserver(AdoptNS, [[WebCoreRenderThemeNotificationObserver alloc] initWithTheme:this]) { [[NSNotificationCenter defaultCenter] addObserver:m_notificationObserver.get() selector:@selector(systemColorsDidChange:) name:NSSystemColorsDidChangeNotification object:nil]; } RenderThemeChromiumMac::~RenderThemeChromiumMac() { [[NSNotificationCenter defaultCenter] removeObserver:m_notificationObserver.get()]; } Color RenderThemeChromiumMac::platformActiveSelectionBackgroundColor() const { NSColor* color = [[NSColor selectedTextBackgroundColor] colorUsingColorSpaceName:NSDeviceRGBColorSpace]; return Color(static_cast(255.0 * [color redComponent]), static_cast(255.0 * [color greenComponent]), static_cast(255.0 * [color blueComponent])); } Color RenderThemeChromiumMac::platformInactiveSelectionBackgroundColor() const { NSColor* color = [[NSColor secondarySelectedControlColor] colorUsingColorSpaceName:NSDeviceRGBColorSpace]; return Color(static_cast(255.0 * [color redComponent]), static_cast(255.0 * [color greenComponent]), static_cast(255.0 * [color blueComponent])); } Color RenderThemeChromiumMac::activeListBoxSelectionBackgroundColor() const { NSColor* color = [[NSColor alternateSelectedControlColor] colorUsingColorSpaceName:NSDeviceRGBColorSpace]; return Color(static_cast(255.0 * [color redComponent]), static_cast(255.0 * [color greenComponent]), static_cast(255.0 * [color blueComponent])); } static FontWeight toFontWeight(NSInteger appKitFontWeight) { ASSERT(appKitFontWeight > 0 && appKitFontWeight < 15); if (appKitFontWeight > 14) appKitFontWeight = 14; else if (appKitFontWeight < 1) appKitFontWeight = 1; static FontWeight fontWeights[] = { FontWeight100, FontWeight100, FontWeight200, FontWeight300, FontWeight400, FontWeight500, FontWeight600, FontWeight600, FontWeight700, FontWeight800, FontWeight800, FontWeight900, FontWeight900, FontWeight900 }; return fontWeights[appKitFontWeight - 1]; } void RenderThemeChromiumMac::systemFont(int cssValueId, Document* document, FontDescription& fontDescription) const { static FontDescription systemFont; static FontDescription smallSystemFont; static FontDescription menuFont; static FontDescription labelFont; static FontDescription miniControlFont; static FontDescription smallControlFont; static FontDescription controlFont; FontDescription* cachedDesc; NSFont* font = nil; switch (cssValueId) { case CSSValueSmallCaption: cachedDesc = &smallSystemFont; if (!smallSystemFont.isAbsoluteSize()) font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; break; case CSSValueMenu: cachedDesc = &menuFont; if (!menuFont.isAbsoluteSize()) font = [NSFont menuFontOfSize:[NSFont systemFontSize]]; break; case CSSValueStatusBar: cachedDesc = &labelFont; if (!labelFont.isAbsoluteSize()) font = [NSFont labelFontOfSize:[NSFont labelFontSize]]; break; case CSSValueWebkitMiniControl: cachedDesc = &miniControlFont; if (!miniControlFont.isAbsoluteSize()) font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSMiniControlSize]]; break; case CSSValueWebkitSmallControl: cachedDesc = &smallControlFont; if (!smallControlFont.isAbsoluteSize()) font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]; break; case CSSValueWebkitControl: cachedDesc = &controlFont; if (!controlFont.isAbsoluteSize()) font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]; break; default: cachedDesc = &systemFont; if (!systemFont.isAbsoluteSize()) font = [NSFont systemFontOfSize:[NSFont systemFontSize]]; } if (font) { NSFontManager *fontManager = [NSFontManager sharedFontManager]; cachedDesc->setIsAbsoluteSize(true); cachedDesc->setGenericFamily(FontDescription::NoFamily); cachedDesc->firstFamily().setFamily([font familyName]); cachedDesc->setSpecifiedSize([font pointSize]); cachedDesc->setWeight(toFontWeight([fontManager weightOfFont:font])); cachedDesc->setItalic([fontManager traitsOfFont:font] & NSItalicFontMask); } fontDescription = *cachedDesc; } static RGBA32 convertNSColorToColor(NSColor *color) { NSColor *colorInColorSpace = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; if (colorInColorSpace) { static const double scaleFactor = nextafter(256.0, 0.0); return makeRGB(static_cast(scaleFactor * [colorInColorSpace redComponent]), static_cast(scaleFactor * [colorInColorSpace greenComponent]), static_cast(scaleFactor * [colorInColorSpace blueComponent])); } // This conversion above can fail if the NSColor in question is an NSPatternColor // (as many system colors are). These colors are actually a repeating pattern // not just a solid color. To work around this we simply draw a 1x1 image of // the color and use that pixel's color. It might be better to use an average of // the colors in the pattern instead. NSBitmapImageRep *offscreenRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil pixelsWide:1 pixelsHigh:1 bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bytesPerRow:4 bitsPerPixel:32]; [NSGraphicsContext saveGraphicsState]; [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:offscreenRep]]; NSEraseRect(NSMakeRect(0, 0, 1, 1)); [color drawSwatchInRect:NSMakeRect(0, 0, 1, 1)]; [NSGraphicsContext restoreGraphicsState]; NSUInteger pixel[4]; [offscreenRep getPixel:pixel atX:0 y:0]; [offscreenRep release]; return makeRGB(pixel[0], pixel[1], pixel[2]); } static RGBA32 menuBackgroundColor() { NSBitmapImageRep *offscreenRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil pixelsWide:1 pixelsHigh:1 bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bytesPerRow:4 bitsPerPixel:32]; CGContextRef context = static_cast([[NSGraphicsContext graphicsContextWithBitmapImageRep:offscreenRep] graphicsPort]); CGRect rect = CGRectMake(0, 0, 1, 1); HIThemeMenuDrawInfo drawInfo; drawInfo.version = 0; drawInfo.menuType = kThemeMenuTypePopUp; HIThemeDrawMenuBackground(&rect, &drawInfo, context, kHIThemeOrientationInverted); NSUInteger pixel[4]; [offscreenRep getPixel:pixel atX:0 y:0]; [offscreenRep release]; return makeRGB(pixel[0], pixel[1], pixel[2]); } void RenderThemeChromiumMac::platformColorsDidChange() { m_systemColorCache.clear(); RenderTheme::platformColorsDidChange(); } Color RenderThemeChromiumMac::systemColor(int cssValueId) const { if (m_systemColorCache.contains(cssValueId)) return m_systemColorCache.get(cssValueId); Color color; switch (cssValueId) { case CSSValueActiveborder: color = convertNSColorToColor([NSColor keyboardFocusIndicatorColor]); break; case CSSValueActivecaption: color = convertNSColorToColor([NSColor windowFrameTextColor]); break; case CSSValueAppworkspace: color = convertNSColorToColor([NSColor headerColor]); break; case CSSValueBackground: // Use theme independent default break; case CSSValueButtonface: // We use this value instead of NSColor's controlColor to avoid website incompatibilities. // We may want to change this to use the NSColor in future. color = 0xFFC0C0C0; break; case CSSValueButtonhighlight: color = convertNSColorToColor([NSColor controlHighlightColor]); break; case CSSValueButtonshadow: color = convertNSColorToColor([NSColor controlShadowColor]); break; case CSSValueButtontext: color = convertNSColorToColor([NSColor controlTextColor]); break; case CSSValueCaptiontext: color = convertNSColorToColor([NSColor textColor]); break; case CSSValueGraytext: color = convertNSColorToColor([NSColor disabledControlTextColor]); break; case CSSValueHighlight: color = convertNSColorToColor([NSColor selectedTextBackgroundColor]); break; case CSSValueHighlighttext: color = convertNSColorToColor([NSColor selectedTextColor]); break; case CSSValueInactiveborder: color = convertNSColorToColor([NSColor controlBackgroundColor]); break; case CSSValueInactivecaption: color = convertNSColorToColor([NSColor controlBackgroundColor]); break; case CSSValueInactivecaptiontext: color = convertNSColorToColor([NSColor textColor]); break; case CSSValueInfobackground: // There is no corresponding NSColor for this so we use a hard coded value. color = 0xFFFBFCC5; break; case CSSValueInfotext: color = convertNSColorToColor([NSColor textColor]); break; case CSSValueMenu: color = menuBackgroundColor(); break; case CSSValueMenutext: color = convertNSColorToColor([NSColor selectedMenuItemTextColor]); break; case CSSValueScrollbar: color = convertNSColorToColor([NSColor scrollBarColor]); break; case CSSValueText: color = convertNSColorToColor([NSColor textColor]); break; case CSSValueThreeddarkshadow: color = convertNSColorToColor([NSColor controlDarkShadowColor]); break; case CSSValueThreedshadow: color = convertNSColorToColor([NSColor shadowColor]); break; case CSSValueThreedface: // We use this value instead of NSColor's controlColor to avoid website incompatibilities. // We may want to change this to use the NSColor in future. color = 0xFFC0C0C0; break; case CSSValueThreedhighlight: color = convertNSColorToColor([NSColor highlightColor]); break; case CSSValueThreedlightshadow: color = convertNSColorToColor([NSColor controlLightHighlightColor]); break; case CSSValueWindow: color = convertNSColorToColor([NSColor windowBackgroundColor]); break; case CSSValueWindowframe: color = convertNSColorToColor([NSColor windowFrameColor]); break; case CSSValueWindowtext: color = convertNSColorToColor([NSColor windowFrameTextColor]); break; } if (!color.isValid()) color = RenderTheme::systemColor(cssValueId); if (color.isValid()) m_systemColorCache.set(cssValueId, color.rgb()); return color; } bool RenderThemeChromiumMac::isControlStyled(const RenderStyle* style, const BorderData& border, const FillLayer& background, const Color& backgroundColor) const { if (style->appearance() == TextFieldPart || style->appearance() == TextAreaPart || style->appearance() == ListboxPart) return style->border() != border; // FIXME: This is horrible, but there is not much else that can be done. Menu lists cannot draw properly when // scaled. They can't really draw properly when transformed either. We can't detect the transform case at style // adjustment time so that will just have to stay broken. We can however detect that we're zooming. If zooming // is in effect we treat it like the control is styled. if (style->appearance() == MenulistPart && style->effectiveZoom() != 1.0f) return true; return RenderTheme::isControlStyled(style, border, background, backgroundColor); } // FIXME: Use the code from the old upstream version, before it was converted to the new theme API in r37731. void RenderThemeChromiumMac::adjustRepaintRect(const RenderObject* o, IntRect& r) { float zoomLevel = o->style()->effectiveZoom(); switch (o->style()->appearance()) { case CheckboxPart: { // Since we query the prototype cell, we need to update its state to match. setCheckboxCellState(o, r); // We inflate the rect as needed to account for padding included in the cell to accommodate the checkbox // shadow" and the check. We don't consider this part of the bounds of the control in WebKit. IntSize size = checkboxSizes()[[checkbox() controlSize]]; size.setHeight(size.height() * zoomLevel); size.setWidth(size.width() * zoomLevel); r = inflateRect(r, size, checkboxMargins(), zoomLevel); break; } case RadioPart: { // Since we query the prototype cell, we need to update its state to match. setRadioCellState(o, r); // We inflate the rect as needed to account for padding included in the cell to accommodate the checkbox // shadow" and the check. We don't consider this part of the bounds of the control in WebKit. IntSize size = radioSizes()[[radio() controlSize]]; size.setHeight(size.height() * zoomLevel); size.setWidth(size.width() * zoomLevel); r = inflateRect(r, size, radioMargins(), zoomLevel); break; } case PushButtonPart: case DefaultButtonPart: case ButtonPart: { // Since we query the prototype cell, we need to update its state to match. setButtonCellState(o, r); // We inflate the rect as needed to account for padding included in the cell to accommodate the checkbox // shadow" and the check. We don't consider this part of the bounds of the control in WebKit. if ([button() bezelStyle] == NSRoundedBezelStyle) { IntSize size = buttonSizes()[[button() controlSize]]; size.setHeight(size.height() * zoomLevel); size.setWidth(r.width()); r = inflateRect(r, size, buttonMargins(), zoomLevel); } break; } case MenulistPart: { setPopupButtonCellState(o, r); IntSize size = popupButtonSizes()[[popupButton() controlSize]]; size.setHeight(size.height() * zoomLevel); size.setWidth(r.width()); r = inflateRect(r, size, popupButtonMargins(), zoomLevel); break; } default: break; } } IntRect RenderThemeChromiumMac::inflateRect(const IntRect& r, const IntSize& size, const int* margins, float zoomLevel) const { // Only do the inflation if the available width/height are too small. Otherwise try to // fit the glow/check space into the available box's width/height. int widthDelta = r.width() - (size.width() + margins[LeftMargin] * zoomLevel + margins[RightMargin] * zoomLevel); int heightDelta = r.height() - (size.height() + margins[TopMargin] * zoomLevel + margins[BottomMargin] * zoomLevel); IntRect result(r); if (widthDelta < 0) { result.setX(result.x() - margins[LeftMargin] * zoomLevel); result.setWidth(result.width() - widthDelta); } if (heightDelta < 0) { result.setY(result.y() - margins[TopMargin] * zoomLevel); result.setHeight(result.height() - heightDelta); } return result; } void RenderThemeChromiumMac::updateCheckedState(NSCell* cell, const RenderObject* o) { bool oldIndeterminate = [cell state] == NSMixedState; bool indeterminate = isIndeterminate(o); bool checked = isChecked(o); if (oldIndeterminate != indeterminate) { [cell setState:indeterminate ? NSMixedState : (checked ? NSOnState : NSOffState)]; return; } bool oldChecked = [cell state] == NSOnState; if (checked != oldChecked) [cell setState:checked ? NSOnState : NSOffState]; } void RenderThemeChromiumMac::updateEnabledState(NSCell* cell, const RenderObject* o) { bool oldEnabled = [cell isEnabled]; bool enabled = isEnabled(o); if (enabled != oldEnabled) [cell setEnabled:enabled]; } void RenderThemeChromiumMac::updateFocusedState(NSCell* cell, const RenderObject* o) { bool oldFocused = [cell showsFirstResponder]; bool focused = isFocused(o) && o->style()->outlineStyleIsAuto(); if (focused != oldFocused) [cell setShowsFirstResponder:focused]; } void RenderThemeChromiumMac::updatePressedState(NSCell* cell, const RenderObject* o) { bool oldPressed = [cell isHighlighted]; bool pressed = (o->element() && o->element()->active()); if (pressed != oldPressed) [cell setHighlighted:pressed]; } // FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731. int RenderThemeChromiumMac::baselinePosition(const RenderObject* o) const { if (o->style()->appearance() == CheckboxPart || o->style()->appearance() == RadioPart) return o->marginTop() + o->height() - 2 * o->style()->effectiveZoom(); // The baseline is 2px up from the bottom of the checkbox/radio in AppKit. return RenderTheme::baselinePosition(o); } bool RenderThemeChromiumMac::controlSupportsTints(const RenderObject* o) const { // An alternate way to implement this would be to get the appropriate cell object // and call the private _needRedrawOnWindowChangedKeyState method. An advantage of // that would be that we would match AppKit behavior more closely, but a disadvantage // would be that we would rely on an AppKit SPI method. if (!isEnabled(o)) return false; // Checkboxes only have tint when checked. if (o->style()->appearance() == CheckboxPart) return isChecked(o); // For now assume other controls have tint if enabled. return true; } NSControlSize RenderThemeChromiumMac::controlSizeForFont(RenderStyle* style) const { int fontSize = style->fontSize(); if (fontSize >= 16) return NSRegularControlSize; if (fontSize >= 11) return NSSmallControlSize; return NSMiniControlSize; } void RenderThemeChromiumMac::setControlSize(NSCell* cell, const IntSize* sizes, const IntSize& minSize, float zoomLevel) { NSControlSize size; if (minSize.width() >= static_cast(sizes[NSRegularControlSize].width() * zoomLevel) && minSize.height() >= static_cast(sizes[NSRegularControlSize].height() * zoomLevel)) size = NSRegularControlSize; else if (minSize.width() >= static_cast(sizes[NSSmallControlSize].width() * zoomLevel) && minSize.height() >= static_cast(sizes[NSSmallControlSize].height() * zoomLevel)) size = NSSmallControlSize; else size = NSMiniControlSize; if (size != [cell controlSize]) // Only update if we have to, since AppKit does work even if the size is the same. [cell setControlSize:size]; } IntSize RenderThemeChromiumMac::sizeForFont(RenderStyle* style, const IntSize* sizes) const { if (style->effectiveZoom() != 1.0f) { IntSize result = sizes[controlSizeForFont(style)]; return IntSize(result.width() * style->effectiveZoom(), result.height() * style->effectiveZoom()); } return sizes[controlSizeForFont(style)]; } IntSize RenderThemeChromiumMac::sizeForSystemFont(RenderStyle* style, const IntSize* sizes) const { if (style->effectiveZoom() != 1.0f) { IntSize result = sizes[controlSizeForSystemFont(style)]; return IntSize(result.width() * style->effectiveZoom(), result.height() * style->effectiveZoom()); } return sizes[controlSizeForSystemFont(style)]; } void RenderThemeChromiumMac::setSizeFromFont(RenderStyle* style, const IntSize* sizes) const { // FIXME: Check is flawed, since it doesn't take min-width/max-width into account. IntSize size = sizeForFont(style, sizes); if (style->width().isIntrinsicOrAuto() && size.width() > 0) style->setWidth(Length(size.width(), Fixed)); if (style->height().isAuto() && size.height() > 0) style->setHeight(Length(size.height(), Fixed)); } void RenderThemeChromiumMac::setFontFromControlSize(CSSStyleSelector* selector, RenderStyle* style, NSControlSize controlSize) const { FontDescription fontDescription; fontDescription.setIsAbsoluteSize(true); fontDescription.setGenericFamily(FontDescription::SerifFamily); NSFont* font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:controlSize]]; fontDescription.firstFamily().setFamily([font familyName]); fontDescription.setComputedSize([font pointSize] * style->effectiveZoom()); fontDescription.setSpecifiedSize([font pointSize] * style->effectiveZoom()); // Reset line height style->setLineHeight(RenderStyle::initialLineHeight()); if (style->setFontDescription(fontDescription)) style->font().update(0); } NSControlSize RenderThemeChromiumMac::controlSizeForSystemFont(RenderStyle* style) const { int fontSize = style->fontSize(); if (fontSize >= [NSFont systemFontSizeForControlSize:NSRegularControlSize]) return NSRegularControlSize; if (fontSize >= [NSFont systemFontSizeForControlSize:NSSmallControlSize]) return NSSmallControlSize; return NSMiniControlSize; } // FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731. bool RenderThemeChromiumMac::paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r) { // Determine the width and height needed for the control and prepare the cell for painting. setCheckboxCellState(o, r); paintInfo.context->save(); float zoomLevel = o->style()->effectiveZoom(); // We inflate the rect as needed to account for padding included in the cell to accommodate the checkbox // shadow" and the check. We don't consider this part of the bounds of the control in WebKit. NSButtonCell* checkbox = this->checkbox(); IntSize size = checkboxSizes()[[checkbox controlSize]]; size.setWidth(size.width() * zoomLevel); size.setHeight(size.height() * zoomLevel); IntRect inflatedRect = inflateRect(r, size, checkboxMargins(), zoomLevel); if (zoomLevel != 1.0f) { inflatedRect.setWidth(inflatedRect.width() / zoomLevel); inflatedRect.setHeight(inflatedRect.height() / zoomLevel); paintInfo.context->translate(inflatedRect.x(), inflatedRect.y()); paintInfo.context->scale(FloatSize(zoomLevel, zoomLevel)); paintInfo.context->translate(-inflatedRect.x(), -inflatedRect.y()); } [checkbox drawWithFrame:NSRect(IntRectToNSRect(inflatedRect)) inView:nil]; [checkbox setControlView:nil]; paintInfo.context->restore(); return false; } // FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731. const IntSize* RenderThemeChromiumMac::checkboxSizes() const { static const IntSize sizes[3] = { IntSize(14, 14), IntSize(12, 12), IntSize(10, 10) }; return sizes; } // FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731. const int* RenderThemeChromiumMac::checkboxMargins() const { static const int margins[3][4] = { { 3, 4, 4, 2 }, { 4, 3, 3, 3 }, { 4, 3, 3, 3 }, }; return margins[[checkbox() controlSize]]; } // FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731. void RenderThemeChromiumMac::setCheckboxCellState(const RenderObject* o, const IntRect& r) { NSButtonCell* checkbox = this->checkbox(); // Set the control size based off the rectangle we're painting into. setControlSize(checkbox, checkboxSizes(), r.size(), o->style()->effectiveZoom()); // Update the various states we respond to. updateCheckedState(checkbox, o); updateEnabledState(checkbox, o); updatePressedState(checkbox, o); updateFocusedState(checkbox, o); } // FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731. void RenderThemeChromiumMac::setCheckboxSize(RenderStyle* style) const { // If the width and height are both specified, then we have nothing to do. if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto()) return; // Use the font size to determine the intrinsic width of the control. setSizeFromFont(style, checkboxSizes()); } // FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731. bool RenderThemeChromiumMac::paintRadio(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r) { // Determine the width and height needed for the control and prepare the cell for painting. setRadioCellState(o, r); paintInfo.context->save(); float zoomLevel = o->style()->effectiveZoom(); // We inflate the rect as needed to account for padding included in the cell to accommodate the checkbox // shadow" and the check. We don't consider this part of the bounds of the control in WebKit. NSButtonCell* radio = this->radio(); IntSize size = radioSizes()[[radio controlSize]]; size.setWidth(size.width() * zoomLevel); size.setHeight(size.height() * zoomLevel); IntRect inflatedRect = inflateRect(r, size, radioMargins(), zoomLevel); if (zoomLevel != 1.0f) { inflatedRect.setWidth(inflatedRect.width() / zoomLevel); inflatedRect.setHeight(inflatedRect.height() / zoomLevel); paintInfo.context->translate(inflatedRect.x(), inflatedRect.y()); paintInfo.context->scale(FloatSize(zoomLevel, zoomLevel)); paintInfo.context->translate(-inflatedRect.x(), -inflatedRect.y()); } [radio drawWithFrame:NSRect(IntRectToNSRect(inflatedRect)) inView:nil]; [radio setControlView:nil]; paintInfo.context->restore(); return false; } // FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731. const IntSize* RenderThemeChromiumMac::radioSizes() const { static const IntSize sizes[3] = { IntSize(14, 15), IntSize(12, 13), IntSize(10, 10) }; return sizes; } // FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731. const int* RenderThemeChromiumMac::radioMargins() const { static const int margins[3][4] = { { 2, 2, 4, 2 }, { 3, 2, 3, 2 }, { 1, 0, 2, 0 }, }; return margins[[radio() controlSize]]; } // FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731. void RenderThemeChromiumMac::setRadioCellState(const RenderObject* o, const IntRect& r) { NSButtonCell* radio = this->radio(); // Set the control size based off the rectangle we're painting into. setControlSize(radio, radioSizes(), r.size(), o->style()->effectiveZoom()); // Update the various states we respond to. updateCheckedState(radio, o); updateEnabledState(radio, o); updatePressedState(radio, o); updateFocusedState(radio, o); } // FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731. void RenderThemeChromiumMac::setRadioSize(RenderStyle* style) const { // If the width and height are both specified, then we have nothing to do. if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto()) return; // Use the font size to determine the intrinsic width of the control. setSizeFromFont(style, radioSizes()); } // FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731. void RenderThemeChromiumMac::setButtonPaddingFromControlSize(RenderStyle* style, NSControlSize size) const { // Just use 8px. AppKit wants to use 11px for mini buttons, but that padding is just too large // for real-world Web sites (creating a huge necessary minimum width for buttons whose space is // by definition constrained, since we select mini only for small cramped environments. // This also guarantees the HTML4