2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #import "RenderThemeMac.h"
23 #import "BitmapImage.h"
25 #import "CSSStyleSelector.h"
26 #import "CSSValueKeywords.h"
30 #import "GraphicsContextCG.h"
31 #import "HTMLInputElement.h"
32 #import "HTMLMediaElement.h"
35 #import "ImageBuffer.h"
36 #import "LocalCurrentGraphicsContext.h"
37 #import "LocalizedStrings.h"
38 #import "MediaControlElements.h"
40 #import "RenderMedia.h"
41 #import "RenderMediaControls.h"
42 #import "RenderSlider.h"
43 #import "RenderView.h"
44 #import "SharedBuffer.h"
45 #import "StringTruncator.h"
46 #import "TimeRanges.h"
48 #import "WebCoreSystemInterface.h"
49 #import "UserAgentStyleSheets.h"
50 #import <Carbon/Carbon.h>
51 #import <Cocoa/Cocoa.h>
52 #import <wtf/RetainPtr.h>
53 #import <wtf/StdLibExtras.h>
56 #import "RenderProgress.h"
59 #include "RenderMeter.h"
60 #include "HTMLMeterElement.h"
66 // The methods in this file are specific to the Mac OS X platform.
68 // FIXME: The platform-independent code in this class should be factored out and merged with RenderThemeSafari.
70 // We estimate the animation rate of a Mac OS X progress bar is 33 fps.
71 // Hard code the value here because we haven't found API for it.
72 const double progressAnimationFrameRate = 0.033;
74 // Mac OS X progress bar animation seems to have 256 frames.
75 const double progressAnimationNumFrames = 256;
77 @interface WebCoreRenderThemeNotificationObserver : NSObject
79 WebCore::RenderTheme *_theme;
82 - (id)initWithTheme:(WebCore::RenderTheme *)theme;
83 - (void)systemColorsDidChange:(NSNotification *)notification;
87 @implementation WebCoreRenderThemeNotificationObserver
89 - (id)initWithTheme:(WebCore::RenderTheme *)theme
91 if (!(self = [super init]))
98 - (void)systemColorsDidChange:(NSNotification *)unusedNotification
100 ASSERT_UNUSED(unusedNotification, [[unusedNotification name] isEqualToString:NSSystemColorsDidChangeNotification]);
101 _theme->platformColorsDidChange();
108 using namespace HTMLNames;
125 PassRefPtr<RenderTheme> RenderTheme::themeForPage(Page*)
127 static RenderTheme* rt = RenderThemeMac::create().releaseRef();
132 PassRefPtr<RenderTheme> RenderThemeMac::create()
134 return adoptRef(new RenderThemeMac);
137 RenderThemeMac::RenderThemeMac()
138 : m_isSliderThumbHorizontalPressed(false)
139 , m_isSliderThumbVerticalPressed(false)
140 , m_notificationObserver(AdoptNS, [[WebCoreRenderThemeNotificationObserver alloc] initWithTheme:this])
142 [[NSNotificationCenter defaultCenter] addObserver:m_notificationObserver.get()
143 selector:@selector(systemColorsDidChange:)
144 name:NSSystemColorsDidChangeNotification
148 RenderThemeMac::~RenderThemeMac()
150 [[NSNotificationCenter defaultCenter] removeObserver:m_notificationObserver.get()];
153 Color RenderThemeMac::platformActiveSelectionBackgroundColor() const
155 NSColor* color = [[NSColor selectedTextBackgroundColor] colorUsingColorSpaceName:NSDeviceRGBColorSpace];
156 return Color(static_cast<int>(255.0 * [color redComponent]), static_cast<int>(255.0 * [color greenComponent]), static_cast<int>(255.0 * [color blueComponent]));
159 Color RenderThemeMac::platformInactiveSelectionBackgroundColor() const
161 NSColor* color = [[NSColor secondarySelectedControlColor] colorUsingColorSpaceName:NSDeviceRGBColorSpace];
162 return Color(static_cast<int>(255.0 * [color redComponent]), static_cast<int>(255.0 * [color greenComponent]), static_cast<int>(255.0 * [color blueComponent]));
165 Color RenderThemeMac::platformActiveListBoxSelectionBackgroundColor() const
167 NSColor* color = [[NSColor alternateSelectedControlColor] colorUsingColorSpaceName:NSDeviceRGBColorSpace];
168 return Color(static_cast<int>(255.0 * [color redComponent]), static_cast<int>(255.0 * [color greenComponent]), static_cast<int>(255.0 * [color blueComponent]));
171 Color RenderThemeMac::platformActiveListBoxSelectionForegroundColor() const
176 Color RenderThemeMac::platformInactiveListBoxSelectionForegroundColor() const
181 Color RenderThemeMac::platformFocusRingColor() const
183 if (usesTestModeFocusRingColor())
184 return oldAquaFocusRingColor();
186 return systemColor(CSSValueWebkitFocusRingColor);
189 Color RenderThemeMac::platformInactiveListBoxSelectionBackgroundColor() const
191 return platformInactiveSelectionBackgroundColor();
194 static FontWeight toFontWeight(NSInteger appKitFontWeight)
196 ASSERT(appKitFontWeight > 0 && appKitFontWeight < 15);
197 if (appKitFontWeight > 14)
198 appKitFontWeight = 14;
199 else if (appKitFontWeight < 1)
200 appKitFontWeight = 1;
202 static FontWeight fontWeights[] = {
218 return fontWeights[appKitFontWeight - 1];
221 void RenderThemeMac::systemFont(int cssValueId, FontDescription& fontDescription) const
223 DEFINE_STATIC_LOCAL(FontDescription, systemFont, ());
224 DEFINE_STATIC_LOCAL(FontDescription, smallSystemFont, ());
225 DEFINE_STATIC_LOCAL(FontDescription, menuFont, ());
226 DEFINE_STATIC_LOCAL(FontDescription, labelFont, ());
227 DEFINE_STATIC_LOCAL(FontDescription, miniControlFont, ());
228 DEFINE_STATIC_LOCAL(FontDescription, smallControlFont, ());
229 DEFINE_STATIC_LOCAL(FontDescription, controlFont, ());
231 FontDescription* cachedDesc;
233 switch (cssValueId) {
234 case CSSValueSmallCaption:
235 cachedDesc = &smallSystemFont;
236 if (!smallSystemFont.isAbsoluteSize())
237 font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
240 cachedDesc = &menuFont;
241 if (!menuFont.isAbsoluteSize())
242 font = [NSFont menuFontOfSize:[NSFont systemFontSize]];
244 case CSSValueStatusBar:
245 cachedDesc = &labelFont;
246 if (!labelFont.isAbsoluteSize())
247 font = [NSFont labelFontOfSize:[NSFont labelFontSize]];
249 case CSSValueWebkitMiniControl:
250 cachedDesc = &miniControlFont;
251 if (!miniControlFont.isAbsoluteSize())
252 font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSMiniControlSize]];
254 case CSSValueWebkitSmallControl:
255 cachedDesc = &smallControlFont;
256 if (!smallControlFont.isAbsoluteSize())
257 font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]];
259 case CSSValueWebkitControl:
260 cachedDesc = &controlFont;
261 if (!controlFont.isAbsoluteSize())
262 font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]];
265 cachedDesc = &systemFont;
266 if (!systemFont.isAbsoluteSize())
267 font = [NSFont systemFontOfSize:[NSFont systemFontSize]];
271 NSFontManager *fontManager = [NSFontManager sharedFontManager];
272 cachedDesc->setIsAbsoluteSize(true);
273 cachedDesc->setGenericFamily(FontDescription::NoFamily);
274 cachedDesc->firstFamily().setFamily([font familyName]);
275 cachedDesc->setSpecifiedSize([font pointSize]);
276 cachedDesc->setWeight(toFontWeight([fontManager weightOfFont:font]));
277 cachedDesc->setItalic([fontManager traitsOfFont:font] & NSItalicFontMask);
279 fontDescription = *cachedDesc;
282 static RGBA32 convertNSColorToColor(NSColor *color)
284 NSColor *colorInColorSpace = [color colorUsingColorSpaceName:NSDeviceRGBColorSpace];
285 if (colorInColorSpace) {
286 static const double scaleFactor = nextafter(256.0, 0.0);
287 return makeRGB(static_cast<int>(scaleFactor * [colorInColorSpace redComponent]),
288 static_cast<int>(scaleFactor * [colorInColorSpace greenComponent]),
289 static_cast<int>(scaleFactor * [colorInColorSpace blueComponent]));
292 // This conversion above can fail if the NSColor in question is an NSPatternColor
293 // (as many system colors are). These colors are actually a repeating pattern
294 // not just a solid color. To work around this we simply draw a 1x1 image of
295 // the color and use that pixel's color. It might be better to use an average of
296 // the colors in the pattern instead.
297 NSBitmapImageRep *offscreenRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil
304 colorSpaceName:NSDeviceRGBColorSpace
308 [NSGraphicsContext saveGraphicsState];
309 [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:offscreenRep]];
310 NSEraseRect(NSMakeRect(0, 0, 1, 1));
311 [color drawSwatchInRect:NSMakeRect(0, 0, 1, 1)];
312 [NSGraphicsContext restoreGraphicsState];
315 [offscreenRep getPixel:pixel atX:0 y:0];
317 [offscreenRep release];
319 return makeRGB(pixel[0], pixel[1], pixel[2]);
322 static RGBA32 menuBackgroundColor()
324 NSBitmapImageRep *offscreenRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil
331 colorSpaceName:NSDeviceRGBColorSpace
335 CGContextRef context = static_cast<CGContextRef>([[NSGraphicsContext graphicsContextWithBitmapImageRep:offscreenRep] graphicsPort]);
336 CGRect rect = CGRectMake(0, 0, 1, 1);
337 HIThemeMenuDrawInfo drawInfo;
338 drawInfo.version = 0;
339 drawInfo.menuType = kThemeMenuTypePopUp;
340 HIThemeDrawMenuBackground(&rect, &drawInfo, context, kHIThemeOrientationInverted);
343 [offscreenRep getPixel:pixel atX:0 y:0];
345 [offscreenRep release];
347 return makeRGB(pixel[0], pixel[1], pixel[2]);
350 void RenderThemeMac::platformColorsDidChange()
352 m_systemColorCache.clear();
353 RenderTheme::platformColorsDidChange();
356 Color RenderThemeMac::systemColor(int cssValueId) const
358 if (m_systemColorCache.contains(cssValueId))
359 return m_systemColorCache.get(cssValueId);
362 switch (cssValueId) {
363 case CSSValueActiveborder:
364 color = convertNSColorToColor([NSColor keyboardFocusIndicatorColor]);
366 case CSSValueActivecaption:
367 color = convertNSColorToColor([NSColor windowFrameTextColor]);
369 case CSSValueAppworkspace:
370 color = convertNSColorToColor([NSColor headerColor]);
372 case CSSValueBackground:
373 // Use theme independent default
375 case CSSValueButtonface:
376 // We use this value instead of NSColor's controlColor to avoid website incompatibilities.
377 // We may want to change this to use the NSColor in future.
380 case CSSValueButtonhighlight:
381 color = convertNSColorToColor([NSColor controlHighlightColor]);
383 case CSSValueButtonshadow:
384 color = convertNSColorToColor([NSColor controlShadowColor]);
386 case CSSValueButtontext:
387 color = convertNSColorToColor([NSColor controlTextColor]);
389 case CSSValueCaptiontext:
390 color = convertNSColorToColor([NSColor textColor]);
392 case CSSValueGraytext:
393 color = convertNSColorToColor([NSColor disabledControlTextColor]);
395 case CSSValueHighlight:
396 color = convertNSColorToColor([NSColor selectedTextBackgroundColor]);
398 case CSSValueHighlighttext:
399 color = convertNSColorToColor([NSColor selectedTextColor]);
401 case CSSValueInactiveborder:
402 color = convertNSColorToColor([NSColor controlBackgroundColor]);
404 case CSSValueInactivecaption:
405 color = convertNSColorToColor([NSColor controlBackgroundColor]);
407 case CSSValueInactivecaptiontext:
408 color = convertNSColorToColor([NSColor textColor]);
410 case CSSValueInfobackground:
411 // There is no corresponding NSColor for this so we use a hard coded value.
414 case CSSValueInfotext:
415 color = convertNSColorToColor([NSColor textColor]);
418 color = menuBackgroundColor();
420 case CSSValueMenutext:
421 color = convertNSColorToColor([NSColor selectedMenuItemTextColor]);
423 case CSSValueScrollbar:
424 color = convertNSColorToColor([NSColor scrollBarColor]);
427 color = convertNSColorToColor([NSColor textColor]);
429 case CSSValueThreeddarkshadow:
430 color = convertNSColorToColor([NSColor controlDarkShadowColor]);
432 case CSSValueThreedshadow:
433 color = convertNSColorToColor([NSColor shadowColor]);
435 case CSSValueThreedface:
436 // We use this value instead of NSColor's controlColor to avoid website incompatibilities.
437 // We may want to change this to use the NSColor in future.
440 case CSSValueThreedhighlight:
441 color = convertNSColorToColor([NSColor highlightColor]);
443 case CSSValueThreedlightshadow:
444 color = convertNSColorToColor([NSColor controlLightHighlightColor]);
446 case CSSValueWebkitFocusRingColor:
447 color = convertNSColorToColor([NSColor keyboardFocusIndicatorColor]);
450 color = convertNSColorToColor([NSColor windowBackgroundColor]);
452 case CSSValueWindowframe:
453 color = convertNSColorToColor([NSColor windowFrameColor]);
455 case CSSValueWindowtext:
456 color = convertNSColorToColor([NSColor windowFrameTextColor]);
460 if (!color.isValid())
461 color = RenderTheme::systemColor(cssValueId);
464 m_systemColorCache.set(cssValueId, color.rgb());
469 bool RenderThemeMac::usesTestModeFocusRingColor() const
471 return WebCore::usesTestModeFocusRingColor();
474 NSView* RenderThemeMac::documentViewFor(RenderObject* o) const
477 return ThemeMac::ensuredView(o->view()->frameView());
479 ASSERT_NOT_REACHED();
484 bool RenderThemeMac::isControlStyled(const RenderStyle* style, const BorderData& border,
485 const FillLayer& background, const Color& backgroundColor) const
487 if (style->appearance() == TextFieldPart || style->appearance() == TextAreaPart || style->appearance() == ListboxPart)
488 return style->border() != border;
490 // FIXME: This is horrible, but there is not much else that can be done. Menu lists cannot draw properly when
491 // scaled. They can't really draw properly when transformed either. We can't detect the transform case at style
492 // adjustment time so that will just have to stay broken. We can however detect that we're zooming. If zooming
493 // is in effect we treat it like the control is styled.
494 if (style->appearance() == MenulistPart && style->effectiveZoom() != 1.0f)
497 return RenderTheme::isControlStyled(style, border, background, backgroundColor);
500 void RenderThemeMac::adjustRepaintRect(const RenderObject* o, IntRect& r)
502 ControlPart part = o->style()->appearance();
509 case SquareButtonPart:
511 case DefaultButtonPart:
513 case InnerSpinButtonPart:
514 return RenderTheme::adjustRepaintRect(o, r);
520 float zoomLevel = o->style()->effectiveZoom();
522 if (part == MenulistPart) {
523 setPopupButtonCellState(o, r);
524 IntSize size = popupButtonSizes()[[popupButton() controlSize]];
525 size.setHeight(size.height() * zoomLevel);
526 size.setWidth(r.width());
527 r = inflateRect(r, size, popupButtonMargins(), zoomLevel);
531 IntRect RenderThemeMac::inflateRect(const IntRect& r, const IntSize& size, const int* margins, float zoomLevel) const
533 // Only do the inflation if the available width/height are too small. Otherwise try to
534 // fit the glow/check space into the available box's width/height.
535 int widthDelta = r.width() - (size.width() + margins[leftMargin] * zoomLevel + margins[rightMargin] * zoomLevel);
536 int heightDelta = r.height() - (size.height() + margins[topMargin] * zoomLevel + margins[bottomMargin] * zoomLevel);
538 if (widthDelta < 0) {
539 result.setX(result.x() - margins[leftMargin] * zoomLevel);
540 result.setWidth(result.width() - widthDelta);
542 if (heightDelta < 0) {
543 result.setY(result.y() - margins[topMargin] * zoomLevel);
544 result.setHeight(result.height() - heightDelta);
549 FloatRect RenderThemeMac::convertToPaintingRect(const RenderObject* inputRenderer, const RenderObject* partRenderer, const FloatRect& inputRect, const IntRect& r) const
551 FloatRect partRect(inputRect);
553 // Compute an offset between the part renderer and the input renderer
554 FloatSize offsetFromInputRenderer;
555 const RenderObject* renderer = partRenderer;
556 while (renderer && renderer != inputRenderer) {
557 RenderObject* containingRenderer = renderer->container();
558 offsetFromInputRenderer -= renderer->offsetFromContainer(containingRenderer, LayoutPoint());
559 renderer = containingRenderer;
561 // If the input renderer was not a container, something went wrong
562 ASSERT(renderer == inputRenderer);
563 // Move the rect into partRenderer's coords
564 partRect.move(offsetFromInputRenderer);
565 // Account for the local drawing offset (tx, ty)
566 partRect.move(r.x(), r.y());
571 void RenderThemeMac::updateCheckedState(NSCell* cell, const RenderObject* o)
573 bool oldIndeterminate = [cell state] == NSMixedState;
574 bool indeterminate = isIndeterminate(o);
575 bool checked = isChecked(o);
577 if (oldIndeterminate != indeterminate) {
578 [cell setState:indeterminate ? NSMixedState : (checked ? NSOnState : NSOffState)];
582 bool oldChecked = [cell state] == NSOnState;
583 if (checked != oldChecked)
584 [cell setState:checked ? NSOnState : NSOffState];
587 void RenderThemeMac::updateEnabledState(NSCell* cell, const RenderObject* o)
589 bool oldEnabled = [cell isEnabled];
590 bool enabled = isEnabled(o);
591 if (enabled != oldEnabled)
592 [cell setEnabled:enabled];
595 void RenderThemeMac::updateFocusedState(NSCell* cell, const RenderObject* o)
597 bool oldFocused = [cell showsFirstResponder];
598 bool focused = isFocused(o) && o->style()->outlineStyleIsAuto();
599 if (focused != oldFocused)
600 [cell setShowsFirstResponder:focused];
603 void RenderThemeMac::updatePressedState(NSCell* cell, const RenderObject* o)
605 bool oldPressed = [cell isHighlighted];
606 bool pressed = (o->node() && o->node()->active());
607 if (pressed != oldPressed)
608 [cell setHighlighted:pressed];
611 bool RenderThemeMac::controlSupportsTints(const RenderObject* o) const
613 // An alternate way to implement this would be to get the appropriate cell object
614 // and call the private _needRedrawOnWindowChangedKeyState method. An advantage of
615 // that would be that we would match AppKit behavior more closely, but a disadvantage
616 // would be that we would rely on an AppKit SPI method.
621 // Checkboxes only have tint when checked.
622 if (o->style()->appearance() == CheckboxPart)
625 // For now assume other controls have tint if enabled.
629 NSControlSize RenderThemeMac::controlSizeForFont(RenderStyle* style) const
631 int fontSize = style->fontSize();
633 return NSRegularControlSize;
635 return NSSmallControlSize;
636 return NSMiniControlSize;
639 void RenderThemeMac::setControlSize(NSCell* cell, const IntSize* sizes, const IntSize& minSize, float zoomLevel)
642 if (minSize.width() >= static_cast<int>(sizes[NSRegularControlSize].width() * zoomLevel) &&
643 minSize.height() >= static_cast<int>(sizes[NSRegularControlSize].height() * zoomLevel))
644 size = NSRegularControlSize;
645 else if (minSize.width() >= static_cast<int>(sizes[NSSmallControlSize].width() * zoomLevel) &&
646 minSize.height() >= static_cast<int>(sizes[NSSmallControlSize].height() * zoomLevel))
647 size = NSSmallControlSize;
649 size = NSMiniControlSize;
650 if (size != [cell controlSize]) // Only update if we have to, since AppKit does work even if the size is the same.
651 [cell setControlSize:size];
654 IntSize RenderThemeMac::sizeForFont(RenderStyle* style, const IntSize* sizes) const
656 if (style->effectiveZoom() != 1.0f) {
657 IntSize result = sizes[controlSizeForFont(style)];
658 return IntSize(result.width() * style->effectiveZoom(), result.height() * style->effectiveZoom());
660 return sizes[controlSizeForFont(style)];
663 IntSize RenderThemeMac::sizeForSystemFont(RenderStyle* style, const IntSize* sizes) const
665 if (style->effectiveZoom() != 1.0f) {
666 IntSize result = sizes[controlSizeForSystemFont(style)];
667 return IntSize(result.width() * style->effectiveZoom(), result.height() * style->effectiveZoom());
669 return sizes[controlSizeForSystemFont(style)];
672 void RenderThemeMac::setSizeFromFont(RenderStyle* style, const IntSize* sizes) const
674 // FIXME: Check is flawed, since it doesn't take min-width/max-width into account.
675 IntSize size = sizeForFont(style, sizes);
676 if (style->width().isIntrinsicOrAuto() && size.width() > 0)
677 style->setWidth(Length(size.width(), Fixed));
678 if (style->height().isAuto() && size.height() > 0)
679 style->setHeight(Length(size.height(), Fixed));
682 void RenderThemeMac::setFontFromControlSize(CSSStyleSelector*, RenderStyle* style, NSControlSize controlSize) const
684 FontDescription fontDescription;
685 fontDescription.setIsAbsoluteSize(true);
686 fontDescription.setGenericFamily(FontDescription::SerifFamily);
688 NSFont* font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:controlSize]];
689 fontDescription.firstFamily().setFamily([font familyName]);
690 fontDescription.setComputedSize([font pointSize] * style->effectiveZoom());
691 fontDescription.setSpecifiedSize([font pointSize] * style->effectiveZoom());
694 style->setLineHeight(RenderStyle::initialLineHeight());
696 if (style->setFontDescription(fontDescription))
697 style->font().update(0);
700 NSControlSize RenderThemeMac::controlSizeForSystemFont(RenderStyle* style) const
702 int fontSize = style->fontSize();
703 if (fontSize >= [NSFont systemFontSizeForControlSize:NSRegularControlSize])
704 return NSRegularControlSize;
705 if (fontSize >= [NSFont systemFontSizeForControlSize:NSSmallControlSize])
706 return NSSmallControlSize;
707 return NSMiniControlSize;
710 bool RenderThemeMac::paintTextField(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
712 LocalCurrentGraphicsContext localContext(paintInfo.context);
713 wkDrawBezeledTextFieldCell(r, isEnabled(o) && !isReadOnlyControl(o));
717 void RenderThemeMac::adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const
721 bool RenderThemeMac::paintCapsLockIndicator(RenderObject*, const PaintInfo& paintInfo, const IntRect& r)
723 if (paintInfo.context->paintingDisabled())
726 LocalCurrentGraphicsContext localContext(paintInfo.context);
727 wkDrawCapsLockIndicator(localContext.cgContext(), r);
732 bool RenderThemeMac::paintTextArea(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
734 LocalCurrentGraphicsContext localContext(paintInfo.context);
735 wkDrawBezeledTextArea(r, isEnabled(o) && !isReadOnlyControl(o));
739 void RenderThemeMac::adjustTextAreaStyle(CSSStyleSelector*, RenderStyle*, Element*) const
743 const int* RenderThemeMac::popupButtonMargins() const
745 static const int margins[3][4] =
751 return margins[[popupButton() controlSize]];
754 const IntSize* RenderThemeMac::popupButtonSizes() const
756 static const IntSize sizes[3] = { IntSize(0, 21), IntSize(0, 18), IntSize(0, 15) };
760 const int* RenderThemeMac::popupButtonPadding(NSControlSize size) const
762 static const int padding[3][4] =
768 return padding[size];
771 bool RenderThemeMac::paintMenuList(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
773 LocalCurrentGraphicsContext localContext(paintInfo.context);
774 setPopupButtonCellState(o, r);
776 NSPopUpButtonCell* popupButton = this->popupButton();
778 float zoomLevel = o->style()->effectiveZoom();
779 IntSize size = popupButtonSizes()[[popupButton controlSize]];
780 size.setHeight(size.height() * zoomLevel);
781 size.setWidth(r.width());
783 // Now inflate it to account for the shadow.
784 IntRect inflatedRect = r;
785 if (r.width() >= minimumMenuListSize(o->style()))
786 inflatedRect = inflateRect(inflatedRect, size, popupButtonMargins(), zoomLevel);
788 GraphicsContextStateSaver stateSaver(*paintInfo.context);
790 // On Leopard, the cell will draw outside of the given rect, so we have to clip to the rect
791 paintInfo.context->clip(inflatedRect);
793 if (zoomLevel != 1.0f) {
794 inflatedRect.setWidth(inflatedRect.width() / zoomLevel);
795 inflatedRect.setHeight(inflatedRect.height() / zoomLevel);
796 paintInfo.context->translate(inflatedRect.x(), inflatedRect.y());
797 paintInfo.context->scale(FloatSize(zoomLevel, zoomLevel));
798 paintInfo.context->translate(-inflatedRect.x(), -inflatedRect.y());
801 [popupButton drawWithFrame:inflatedRect inView:documentViewFor(o)];
802 [popupButton setControlView:nil];
807 #if ENABLE(METER_TAG)
809 IntSize RenderThemeMac::meterSizeForBounds(const RenderMeter* renderMeter, const IntRect& bounds) const
811 if (NoControlPart == renderMeter->style()->appearance())
812 return bounds.size();
814 NSLevelIndicatorCell* cell = levelIndicatorFor(renderMeter);
815 // Makes enough room for cell's intrinsic size.
816 NSSize cellSize = [cell cellSizeForBounds:IntRect(IntPoint(), bounds.size())];
817 return IntSize(bounds.width() < cellSize.width ? cellSize.width : bounds.width(),
818 bounds.height() < cellSize.height ? cellSize.height : bounds.height());
821 bool RenderThemeMac::paintMeter(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
823 if (!renderObject->isMeter())
826 LocalCurrentGraphicsContext localContext(paintInfo.context);
828 NSLevelIndicatorCell* cell = levelIndicatorFor(toRenderMeter(renderObject));
829 GraphicsContextStateSaver stateSaver(*paintInfo.context);
831 [cell drawWithFrame:rect inView:documentViewFor(renderObject)];
832 [cell setControlView:nil];
836 bool RenderThemeMac::supportsMeter(ControlPart part) const
839 case RelevancyLevelIndicatorPart:
840 case DiscreteCapacityLevelIndicatorPart:
841 case RatingLevelIndicatorPart:
843 case ContinuousCapacityLevelIndicatorPart:
850 NSLevelIndicatorStyle RenderThemeMac::levelIndicatorStyleFor(ControlPart part) const
853 case RelevancyLevelIndicatorPart:
854 return NSRelevancyLevelIndicatorStyle;
855 case DiscreteCapacityLevelIndicatorPart:
856 return NSDiscreteCapacityLevelIndicatorStyle;
857 case RatingLevelIndicatorPart:
858 return NSRatingLevelIndicatorStyle;
860 case ContinuousCapacityLevelIndicatorPart:
862 return NSContinuousCapacityLevelIndicatorStyle;
867 NSLevelIndicatorCell* RenderThemeMac::levelIndicatorFor(const RenderMeter* renderMeter) const
869 RenderStyle* style = renderMeter->style();
870 ASSERT(style->appearance() != NoControlPart);
872 if (!m_levelIndicator)
873 m_levelIndicator.adoptNS([[NSLevelIndicatorCell alloc] initWithLevelIndicatorStyle:NSContinuousCapacityLevelIndicatorStyle]);
874 NSLevelIndicatorCell* cell = m_levelIndicator.get();
876 HTMLMeterElement* element = static_cast<HTMLMeterElement*>(renderMeter->node());
877 double value = element->value();
879 // Because NSLevelIndicatorCell does not support optimum-in-the-middle type coloring,
880 // we explicitly control the color instead giving low and high value to NSLevelIndicatorCell as is.
881 switch (element->gaugeRegion()) {
882 case HTMLMeterElement::GaugeRegionOptimum:
883 // Make meter the green
884 [cell setWarningValue:value + 1];
885 [cell setCriticalValue:value + 2];
887 case HTMLMeterElement::GaugeRegionSuboptimal:
888 // Make the meter yellow
889 [cell setWarningValue:value - 1];
890 [cell setCriticalValue:value + 1];
892 case HTMLMeterElement::GaugeRegionEvenLessGood:
893 // Make the meter red
894 [cell setWarningValue:value - 2];
895 [cell setCriticalValue:value - 1];
899 [cell setLevelIndicatorStyle:levelIndicatorStyleFor(style->appearance())];
900 [cell setBaseWritingDirection:style->isLeftToRightDirection() ? NSWritingDirectionLeftToRight : NSWritingDirectionRightToLeft];
901 [cell setMinValue:element->min()];
902 [cell setMaxValue:element->max()];
903 RetainPtr<NSNumber> valueObject = [NSNumber numberWithDouble:value];
904 [cell setObjectValue:valueObject.get()];
911 #if ENABLE(PROGRESS_TAG)
913 double RenderThemeMac::animationRepeatIntervalForProgressBar(RenderProgress*) const
915 return progressAnimationFrameRate;
918 double RenderThemeMac::animationDurationForProgressBar(RenderProgress*) const
920 return progressAnimationNumFrames * progressAnimationFrameRate;
923 void RenderThemeMac::adjustProgressBarStyle(CSSStyleSelector*, RenderStyle*, Element*) const
927 bool RenderThemeMac::paintProgressBar(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
929 if (!renderObject->isProgress())
932 RenderProgress* renderProgress = toRenderProgress(renderObject);
933 HIThemeTrackDrawInfo trackInfo;
934 trackInfo.version = 0;
935 trackInfo.kind = renderProgress->position() < 0 ? kThemeLargeIndeterminateBar : kThemeLargeProgressBar;
936 trackInfo.bounds = IntRect(IntPoint(), rect.size());
938 trackInfo.max = numeric_limits<SInt32>::max();
939 trackInfo.value = lround(renderProgress->position() * nextafter(trackInfo.max, 0));
940 trackInfo.trackInfo.progress.phase = lround(renderProgress->animationProgress() * nextafter(progressAnimationNumFrames, 0));
941 trackInfo.attributes = kThemeTrackHorizontal;
942 trackInfo.enableState = isActive(renderObject) ? kThemeTrackActive : kThemeTrackInactive;
943 trackInfo.reserved = 0;
944 trackInfo.filler1 = 0;
946 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(rect.size());
950 ContextContainer cgContextContainer(imageBuffer->context());
951 CGContextRef cgContext = cgContextContainer.context();
952 HIThemeDrawTrack(&trackInfo, 0, cgContext, kHIThemeOrientationNormal);
954 GraphicsContextStateSaver stateSaver(*paintInfo.context);
956 if (!renderProgress->style()->isLeftToRightDirection()) {
957 paintInfo.context->translate(2 * rect.x() + rect.width(), 0);
958 paintInfo.context->scale(FloatSize(-1, 1));
961 paintInfo.context->drawImageBuffer(imageBuffer.get(), ColorSpaceDeviceRGB, rect.location());
966 const float baseFontSize = 11.0f;
967 const float baseArrowHeight = 4.0f;
968 const float baseArrowWidth = 5.0f;
969 const float baseSpaceBetweenArrows = 2.0f;
970 const int arrowPaddingLeft = 6;
971 const int arrowPaddingRight = 6;
972 const int paddingBeforeSeparator = 4;
973 const int baseBorderRadius = 5;
974 const int styledPopupPaddingLeft = 8;
975 const int styledPopupPaddingTop = 1;
976 const int styledPopupPaddingBottom = 2;
978 static void TopGradientInterpolate(void*, const CGFloat* inData, CGFloat* outData)
980 static float dark[4] = { 1.0f, 1.0f, 1.0f, 0.4f };
981 static float light[4] = { 1.0f, 1.0f, 1.0f, 0.15f };
984 for (i = 0; i < 4; i++)
985 outData[i] = (1.0f - a) * dark[i] + a * light[i];
988 static void BottomGradientInterpolate(void*, const CGFloat* inData, CGFloat* outData)
990 static float dark[4] = { 1.0f, 1.0f, 1.0f, 0.0f };
991 static float light[4] = { 1.0f, 1.0f, 1.0f, 0.3f };
994 for (i = 0; i < 4; i++)
995 outData[i] = (1.0f - a) * dark[i] + a * light[i];
998 static void MainGradientInterpolate(void*, const CGFloat* inData, CGFloat* outData)
1000 static float dark[4] = { 0.0f, 0.0f, 0.0f, 0.15f };
1001 static float light[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
1002 float a = inData[0];
1004 for (i = 0; i < 4; i++)
1005 outData[i] = (1.0f - a) * dark[i] + a * light[i];
1008 static void TrackGradientInterpolate(void*, const CGFloat* inData, CGFloat* outData)
1010 static float dark[4] = { 0.0f, 0.0f, 0.0f, 0.678f };
1011 static float light[4] = { 0.0f, 0.0f, 0.0f, 0.13f };
1012 float a = inData[0];
1014 for (i = 0; i < 4; i++)
1015 outData[i] = (1.0f - a) * dark[i] + a * light[i];
1018 void RenderThemeMac::paintMenuListButtonGradients(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1023 ContextContainer cgContextContainer(paintInfo.context);
1024 CGContextRef context = cgContextContainer.context();
1026 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1028 RoundedRect border = o->style()->getRoundedBorderFor(r);
1029 int radius = border.radii().topLeft().width();
1031 CGColorSpaceRef cspace = deviceRGBColorSpaceRef();
1033 FloatRect topGradient(r.x(), r.y(), r.width(), r.height() / 2.0f);
1034 struct CGFunctionCallbacks topCallbacks = { 0, TopGradientInterpolate, NULL };
1035 RetainPtr<CGFunctionRef> topFunction(AdoptCF, CGFunctionCreate(NULL, 1, NULL, 4, NULL, &topCallbacks));
1036 RetainPtr<CGShadingRef> topShading(AdoptCF, CGShadingCreateAxial(cspace, CGPointMake(topGradient.x(), topGradient.y()), CGPointMake(topGradient.x(), topGradient.maxY()), topFunction.get(), false, false));
1038 FloatRect bottomGradient(r.x() + radius, r.y() + r.height() / 2.0f, r.width() - 2.0f * radius, r.height() / 2.0f);
1039 struct CGFunctionCallbacks bottomCallbacks = { 0, BottomGradientInterpolate, NULL };
1040 RetainPtr<CGFunctionRef> bottomFunction(AdoptCF, CGFunctionCreate(NULL, 1, NULL, 4, NULL, &bottomCallbacks));
1041 RetainPtr<CGShadingRef> bottomShading(AdoptCF, CGShadingCreateAxial(cspace, CGPointMake(bottomGradient.x(), bottomGradient.y()), CGPointMake(bottomGradient.x(), bottomGradient.maxY()), bottomFunction.get(), false, false));
1043 struct CGFunctionCallbacks mainCallbacks = { 0, MainGradientInterpolate, NULL };
1044 RetainPtr<CGFunctionRef> mainFunction(AdoptCF, CGFunctionCreate(NULL, 1, NULL, 4, NULL, &mainCallbacks));
1045 RetainPtr<CGShadingRef> mainShading(AdoptCF, CGShadingCreateAxial(cspace, CGPointMake(r.x(), r.y()), CGPointMake(r.x(), r.maxY()), mainFunction.get(), false, false));
1047 RetainPtr<CGShadingRef> leftShading(AdoptCF, CGShadingCreateAxial(cspace, CGPointMake(r.x(), r.y()), CGPointMake(r.x() + radius, r.y()), mainFunction.get(), false, false));
1049 RetainPtr<CGShadingRef> rightShading(AdoptCF, CGShadingCreateAxial(cspace, CGPointMake(r.maxX(), r.y()), CGPointMake(r.maxX() - radius, r.y()), mainFunction.get(), false, false));
1052 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1053 CGContextClipToRect(context, r);
1054 paintInfo.context->addRoundedRectClip(border);
1055 context = cgContextContainer.context();
1056 CGContextDrawShading(context, mainShading.get());
1060 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1061 CGContextClipToRect(context, topGradient);
1062 paintInfo.context->addRoundedRectClip(RoundedRect(enclosingLayoutRect(topGradient), border.radii().topLeft(), border.radii().topRight(), IntSize(), IntSize()));
1063 context = cgContextContainer.context();
1064 CGContextDrawShading(context, topShading.get());
1067 if (!bottomGradient.isEmpty()) {
1068 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1069 CGContextClipToRect(context, bottomGradient);
1070 paintInfo.context->addRoundedRectClip(RoundedRect(enclosingLayoutRect(bottomGradient), IntSize(), IntSize(), border.radii().bottomLeft(), border.radii().bottomRight()));
1071 context = cgContextContainer.context();
1072 CGContextDrawShading(context, bottomShading.get());
1076 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1077 CGContextClipToRect(context, r);
1078 paintInfo.context->addRoundedRectClip(border);
1079 context = cgContextContainer.context();
1080 CGContextDrawShading(context, leftShading.get());
1081 CGContextDrawShading(context, rightShading.get());
1085 bool RenderThemeMac::paintMenuListButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1087 IntRect bounds = IntRect(r.x() + o->style()->borderLeftWidth(),
1088 r.y() + o->style()->borderTopWidth(),
1089 r.width() - o->style()->borderLeftWidth() - o->style()->borderRightWidth(),
1090 r.height() - o->style()->borderTopWidth() - o->style()->borderBottomWidth());
1091 // Draw the gradients to give the styled popup menu a button appearance
1092 paintMenuListButtonGradients(o, paintInfo, bounds);
1094 // Since we actually know the size of the control here, we restrict the font scale to make sure the arrows will fit vertically in the bounds
1095 float fontScale = min(o->style()->fontSize() / baseFontSize, bounds.height() / (baseArrowHeight * 2 + baseSpaceBetweenArrows));
1096 float centerY = bounds.y() + bounds.height() / 2.0f;
1097 float arrowHeight = baseArrowHeight * fontScale;
1098 float arrowWidth = baseArrowWidth * fontScale;
1099 float leftEdge = bounds.maxX() - arrowPaddingRight * o->style()->effectiveZoom() - arrowWidth;
1100 float spaceBetweenArrows = baseSpaceBetweenArrows * fontScale;
1102 if (bounds.width() < arrowWidth + arrowPaddingLeft * o->style()->effectiveZoom())
1105 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1107 paintInfo.context->setFillColor(o->style()->visitedDependentColor(CSSPropertyColor), o->style()->colorSpace());
1108 paintInfo.context->setStrokeStyle(NoStroke);
1110 FloatPoint arrow1[3];
1111 arrow1[0] = FloatPoint(leftEdge, centerY - spaceBetweenArrows / 2.0f);
1112 arrow1[1] = FloatPoint(leftEdge + arrowWidth, centerY - spaceBetweenArrows / 2.0f);
1113 arrow1[2] = FloatPoint(leftEdge + arrowWidth / 2.0f, centerY - spaceBetweenArrows / 2.0f - arrowHeight);
1115 // Draw the top arrow
1116 paintInfo.context->drawConvexPolygon(3, arrow1, true);
1118 FloatPoint arrow2[3];
1119 arrow2[0] = FloatPoint(leftEdge, centerY + spaceBetweenArrows / 2.0f);
1120 arrow2[1] = FloatPoint(leftEdge + arrowWidth, centerY + spaceBetweenArrows / 2.0f);
1121 arrow2[2] = FloatPoint(leftEdge + arrowWidth / 2.0f, centerY + spaceBetweenArrows / 2.0f + arrowHeight);
1123 // Draw the bottom arrow
1124 paintInfo.context->drawConvexPolygon(3, arrow2, true);
1126 Color leftSeparatorColor(0, 0, 0, 40);
1127 Color rightSeparatorColor(255, 255, 255, 40);
1129 // FIXME: Should the separator thickness and space be scaled up by fontScale?
1130 int separatorSpace = 2; // Deliberately ignores zoom since it looks nicer if it stays thin.
1131 int leftEdgeOfSeparator = static_cast<int>(leftEdge - arrowPaddingLeft * o->style()->effectiveZoom()); // FIXME: Round?
1133 // Draw the separator to the left of the arrows
1134 paintInfo.context->setStrokeThickness(1.0f); // Deliberately ignores zoom since it looks nicer if it stays thin.
1135 paintInfo.context->setStrokeStyle(SolidStroke);
1136 paintInfo.context->setStrokeColor(leftSeparatorColor, ColorSpaceDeviceRGB);
1137 paintInfo.context->drawLine(IntPoint(leftEdgeOfSeparator, bounds.y()),
1138 IntPoint(leftEdgeOfSeparator, bounds.maxY()));
1140 paintInfo.context->setStrokeColor(rightSeparatorColor, ColorSpaceDeviceRGB);
1141 paintInfo.context->drawLine(IntPoint(leftEdgeOfSeparator + separatorSpace, bounds.y()),
1142 IntPoint(leftEdgeOfSeparator + separatorSpace, bounds.maxY()));
1146 static const IntSize* menuListButtonSizes()
1148 static const IntSize sizes[3] = { IntSize(0, 21), IntSize(0, 18), IntSize(0, 15) };
1152 void RenderThemeMac::adjustMenuListStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
1154 NSControlSize controlSize = controlSizeForFont(style);
1156 style->resetBorder();
1157 style->resetPadding();
1159 // Height is locked to auto.
1160 style->setHeight(Length(Auto));
1162 // White-space is locked to pre
1163 style->setWhiteSpace(PRE);
1165 // Set the foreground color to black or gray when we have the aqua look.
1166 // Cast to RGB32 is to work around a compiler bug.
1167 style->setColor(e && e->isEnabledFormControl() ? static_cast<RGBA32>(Color::black) : Color::darkGray);
1169 // Set the button's vertical size.
1170 setSizeFromFont(style, menuListButtonSizes());
1172 // Our font is locked to the appropriate system font size for the control. To clarify, we first use the CSS-specified font to figure out
1173 // a reasonable control size, but once that control size is determined, we throw that font away and use the appropriate
1174 // system font for the control size instead.
1175 setFontFromControlSize(selector, style, controlSize);
1177 style->setBoxShadow(nullptr);
1180 int RenderThemeMac::popupInternalPaddingLeft(RenderStyle* style) const
1182 if (style->appearance() == MenulistPart)
1183 return popupButtonPadding(controlSizeForFont(style))[leftPadding] * style->effectiveZoom();
1184 if (style->appearance() == MenulistButtonPart)
1185 return styledPopupPaddingLeft * style->effectiveZoom();
1189 int RenderThemeMac::popupInternalPaddingRight(RenderStyle* style) const
1191 if (style->appearance() == MenulistPart)
1192 return popupButtonPadding(controlSizeForFont(style))[rightPadding] * style->effectiveZoom();
1193 if (style->appearance() == MenulistButtonPart) {
1194 float fontScale = style->fontSize() / baseFontSize;
1195 float arrowWidth = baseArrowWidth * fontScale;
1196 return static_cast<int>(ceilf(arrowWidth + (arrowPaddingLeft + arrowPaddingRight + paddingBeforeSeparator) * style->effectiveZoom()));
1201 int RenderThemeMac::popupInternalPaddingTop(RenderStyle* style) const
1203 if (style->appearance() == MenulistPart)
1204 return popupButtonPadding(controlSizeForFont(style))[topPadding] * style->effectiveZoom();
1205 if (style->appearance() == MenulistButtonPart)
1206 return styledPopupPaddingTop * style->effectiveZoom();
1210 int RenderThemeMac::popupInternalPaddingBottom(RenderStyle* style) const
1212 if (style->appearance() == MenulistPart)
1213 return popupButtonPadding(controlSizeForFont(style))[bottomPadding] * style->effectiveZoom();
1214 if (style->appearance() == MenulistButtonPart)
1215 return styledPopupPaddingBottom * style->effectiveZoom();
1219 void RenderThemeMac::adjustMenuListButtonStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
1221 float fontScale = style->fontSize() / baseFontSize;
1223 style->resetPadding();
1224 style->setBorderRadius(IntSize(int(baseBorderRadius + fontScale - 1), int(baseBorderRadius + fontScale - 1))); // FIXME: Round up?
1226 const int minHeight = 15;
1227 style->setMinHeight(Length(minHeight, Fixed));
1229 style->setLineHeight(RenderStyle::initialLineHeight());
1232 void RenderThemeMac::setPopupButtonCellState(const RenderObject* o, const IntRect& r)
1234 NSPopUpButtonCell* popupButton = this->popupButton();
1236 // Set the control size based off the rectangle we're painting into.
1237 setControlSize(popupButton, popupButtonSizes(), r.size(), o->style()->effectiveZoom());
1239 // Update the various states we respond to.
1240 updateActiveState(popupButton, o);
1241 updateCheckedState(popupButton, o);
1242 updateEnabledState(popupButton, o);
1243 updatePressedState(popupButton, o);
1244 updateFocusedState(popupButton, o);
1247 const IntSize* RenderThemeMac::menuListSizes() const
1249 static const IntSize sizes[3] = { IntSize(9, 0), IntSize(5, 0), IntSize(0, 0) };
1253 int RenderThemeMac::minimumMenuListSize(RenderStyle* style) const
1255 return sizeForSystemFont(style, menuListSizes()).width();
1258 const int trackWidth = 5;
1259 const int trackRadius = 2;
1261 void RenderThemeMac::adjustSliderTrackStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
1263 style->setBoxShadow(nullptr);
1266 bool RenderThemeMac::paintSliderTrack(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1269 float zoomLevel = o->style()->effectiveZoom();
1270 float zoomedTrackWidth = trackWidth * zoomLevel;
1272 if (o->style()->appearance() == SliderHorizontalPart || o->style()->appearance() == MediaSliderPart) {
1273 bounds.setHeight(zoomedTrackWidth);
1274 bounds.setY(r.y() + r.height() / 2 - zoomedTrackWidth / 2);
1275 } else if (o->style()->appearance() == SliderVerticalPart) {
1276 bounds.setWidth(zoomedTrackWidth);
1277 bounds.setX(r.x() + r.width() / 2 - zoomedTrackWidth / 2);
1280 LocalCurrentGraphicsContext localContext(paintInfo.context);
1281 CGContextRef context = localContext.cgContext();
1282 CGColorSpaceRef cspace = deviceRGBColorSpaceRef();
1284 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1285 CGContextClipToRect(context, bounds);
1287 struct CGFunctionCallbacks mainCallbacks = { 0, TrackGradientInterpolate, NULL };
1288 RetainPtr<CGFunctionRef> mainFunction(AdoptCF, CGFunctionCreate(NULL, 1, NULL, 4, NULL, &mainCallbacks));
1289 RetainPtr<CGShadingRef> mainShading;
1290 if (o->style()->appearance() == SliderVerticalPart)
1291 mainShading.adoptCF(CGShadingCreateAxial(cspace, CGPointMake(bounds.x(), bounds.maxY()), CGPointMake(bounds.maxX(), bounds.maxY()), mainFunction.get(), false, false));
1293 mainShading.adoptCF(CGShadingCreateAxial(cspace, CGPointMake(bounds.x(), bounds.y()), CGPointMake(bounds.x(), bounds.maxY()), mainFunction.get(), false, false));
1295 IntSize radius(trackRadius, trackRadius);
1296 paintInfo.context->addRoundedRectClip(RoundedRect(bounds, radius, radius, radius, radius));
1297 context = localContext.cgContext();
1298 CGContextDrawShading(context, mainShading.get());
1303 void RenderThemeMac::adjustSliderThumbStyle(CSSStyleSelector* selector, RenderStyle* style, Element* element) const
1305 RenderTheme::adjustSliderThumbStyle(selector, style, element);
1306 style->setBoxShadow(nullptr);
1309 const float verticalSliderHeightPadding = 0.1f;
1311 bool RenderThemeMac::paintSliderThumb(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1313 NSSliderCell* sliderThumbCell = o->style()->appearance() == SliderThumbVerticalPart
1314 ? sliderThumbVertical()
1315 : sliderThumbHorizontal();
1317 LocalCurrentGraphicsContext localContext(paintInfo.context);
1319 // Update the various states we respond to.
1320 updateActiveState(sliderThumbCell, o);
1321 updateEnabledState(sliderThumbCell, o);
1322 updateFocusedState(sliderThumbCell, (o->node() && o->node()->focusDelegate()->renderer()) ? o->node()->focusDelegate()->renderer() : o);
1324 // Update the pressed state using the NSCell tracking methods, since that's how NSSliderCell keeps track of it.
1326 if (o->style()->appearance() == SliderThumbVerticalPart)
1327 oldPressed = m_isSliderThumbVerticalPressed;
1329 oldPressed = m_isSliderThumbHorizontalPressed;
1331 bool pressed = isPressed(o);
1333 if (o->style()->appearance() == SliderThumbVerticalPart)
1334 m_isSliderThumbVerticalPressed = pressed;
1336 m_isSliderThumbHorizontalPressed = pressed;
1338 if (pressed != oldPressed) {
1340 [sliderThumbCell startTrackingAt:NSPoint() inView:nil];
1342 [sliderThumbCell stopTracking:NSPoint() at:NSPoint() inView:nil mouseIsUp:YES];
1345 FloatRect bounds = r;
1346 // Make the height of the vertical slider slightly larger so NSSliderCell will draw a vertical slider.
1347 if (o->style()->appearance() == SliderThumbVerticalPart)
1348 bounds.setHeight(bounds.height() + verticalSliderHeightPadding * o->style()->effectiveZoom());
1350 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1351 float zoomLevel = o->style()->effectiveZoom();
1353 FloatRect unzoomedRect = bounds;
1354 if (zoomLevel != 1.0f) {
1355 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
1356 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
1357 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y());
1358 paintInfo.context->scale(FloatSize(zoomLevel, zoomLevel));
1359 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y());
1363 // Workaround for <rdar://problem/9421781>.
1364 if (!o->view()->frameView()->documentView()) {
1365 paintInfo.context->translate(0, unzoomedRect.y());
1366 paintInfo.context->scale(FloatSize(1, -1));
1367 paintInfo.context->translate(0, -(unzoomedRect.y() + unzoomedRect.height()));
1369 #elif PLATFORM(CHROMIUM)
1370 paintInfo.context->translate(0, unzoomedRect.y());
1371 paintInfo.context->scale(FloatSize(1, -1));
1372 paintInfo.context->translate(0, -(unzoomedRect.y() + unzoomedRect.height()));
1375 [sliderThumbCell drawInteriorWithFrame:unzoomedRect inView:documentViewFor(o)];
1376 [sliderThumbCell setControlView:nil];
1381 bool RenderThemeMac::paintSearchField(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1383 LocalCurrentGraphicsContext localContext(paintInfo.context);
1384 NSSearchFieldCell* search = this->search();
1386 setSearchCellState(o, r);
1388 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1390 float zoomLevel = o->style()->effectiveZoom();
1392 IntRect unzoomedRect = r;
1394 if (zoomLevel != 1.0f) {
1395 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
1396 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
1397 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y());
1398 paintInfo.context->scale(FloatSize(zoomLevel, zoomLevel));
1399 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y());
1402 // Set the search button to nil before drawing. Then reset it so we can draw it later.
1403 [search setSearchButtonCell:nil];
1405 [search drawWithFrame:NSRect(unzoomedRect) inView:documentViewFor(o)];
1407 [search setControlView:nil];
1408 [search resetSearchButtonCell];
1413 void RenderThemeMac::setSearchCellState(RenderObject* o, const IntRect&)
1415 NSSearchFieldCell* search = this->search();
1417 [search setControlSize:controlSizeForFont(o->style())];
1419 // Update the various states we respond to.
1420 updateActiveState(search, o);
1421 updateEnabledState(search, o);
1422 updateFocusedState(search, o);
1425 const IntSize* RenderThemeMac::searchFieldSizes() const
1427 static const IntSize sizes[3] = { IntSize(0, 22), IntSize(0, 19), IntSize(0, 17) };
1431 void RenderThemeMac::setSearchFieldSize(RenderStyle* style) const
1433 // If the width and height are both specified, then we have nothing to do.
1434 if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
1437 // Use the font size to determine the intrinsic width of the control.
1438 setSizeFromFont(style, searchFieldSizes());
1441 void RenderThemeMac::adjustSearchFieldStyle(CSSStyleSelector* selector, RenderStyle* style, Element*) const
1444 style->resetBorder();
1445 const short borderWidth = 2 * style->effectiveZoom();
1446 style->setBorderLeftWidth(borderWidth);
1447 style->setBorderLeftStyle(INSET);
1448 style->setBorderRightWidth(borderWidth);
1449 style->setBorderRightStyle(INSET);
1450 style->setBorderBottomWidth(borderWidth);
1451 style->setBorderBottomStyle(INSET);
1452 style->setBorderTopWidth(borderWidth);
1453 style->setBorderTopStyle(INSET);
1456 style->setHeight(Length(Auto));
1457 setSearchFieldSize(style);
1459 // Override padding size to match AppKit text positioning.
1460 const int padding = 1 * style->effectiveZoom();
1461 style->setPaddingLeft(Length(padding, Fixed));
1462 style->setPaddingRight(Length(padding, Fixed));
1463 style->setPaddingTop(Length(padding, Fixed));
1464 style->setPaddingBottom(Length(padding, Fixed));
1466 NSControlSize controlSize = controlSizeForFont(style);
1467 setFontFromControlSize(selector, style, controlSize);
1469 style->setBoxShadow(nullptr);
1472 bool RenderThemeMac::paintSearchFieldCancelButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1474 Node* input = o->node()->shadowAncestorNode();
1475 if (!input->renderer()->isBox())
1478 LocalCurrentGraphicsContext localContext(paintInfo.context);
1479 setSearchCellState(input->renderer(), r);
1481 NSSearchFieldCell* search = this->search();
1483 updateActiveState([search cancelButtonCell], o);
1484 updatePressedState([search cancelButtonCell], o);
1486 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1488 float zoomLevel = o->style()->effectiveZoom();
1490 FloatRect localBounds = [search cancelButtonRectForBounds:NSRect(input->renderBox()->borderBoxRect())];
1492 #if ENABLE(INPUT_SPEECH)
1493 // Take care of cases where the cancel button was not aligned with the right border of the input element (for e.g.
1494 // when speech input is enabled for the input element.
1495 IntRect absBoundingBox = input->renderer()->absoluteBoundingBoxRect();
1496 int absRight = absBoundingBox.x() + absBoundingBox.width() - input->renderBox()->paddingRight() - input->renderBox()->borderRight();
1497 int spaceToRightOfCancelButton = absRight - (r.x() + r.width());
1498 localBounds.setX(localBounds.x() - spaceToRightOfCancelButton);
1501 localBounds = convertToPaintingRect(input->renderer(), o, localBounds, r);
1503 FloatRect unzoomedRect(localBounds);
1504 if (zoomLevel != 1.0f) {
1505 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
1506 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
1507 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y());
1508 paintInfo.context->scale(FloatSize(zoomLevel, zoomLevel));
1509 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y());
1512 [[search cancelButtonCell] drawWithFrame:unzoomedRect inView:documentViewFor(o)];
1513 [[search cancelButtonCell] setControlView:nil];
1517 const IntSize* RenderThemeMac::cancelButtonSizes() const
1519 static const IntSize sizes[3] = { IntSize(16, 13), IntSize(13, 11), IntSize(13, 9) };
1523 void RenderThemeMac::adjustSearchFieldCancelButtonStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
1525 IntSize size = sizeForSystemFont(style, cancelButtonSizes());
1526 style->setWidth(Length(size.width(), Fixed));
1527 style->setHeight(Length(size.height(), Fixed));
1528 style->setBoxShadow(nullptr);
1531 const IntSize* RenderThemeMac::resultsButtonSizes() const
1533 static const IntSize sizes[3] = { IntSize(19, 13), IntSize(17, 11), IntSize(17, 9) };
1537 const int emptyResultsOffset = 9;
1538 void RenderThemeMac::adjustSearchFieldDecorationStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
1540 IntSize size = sizeForSystemFont(style, resultsButtonSizes());
1541 style->setWidth(Length(size.width() - emptyResultsOffset, Fixed));
1542 style->setHeight(Length(size.height(), Fixed));
1543 style->setBoxShadow(nullptr);
1546 bool RenderThemeMac::paintSearchFieldDecoration(RenderObject*, const PaintInfo&, const IntRect&)
1551 void RenderThemeMac::adjustSearchFieldResultsDecorationStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
1553 IntSize size = sizeForSystemFont(style, resultsButtonSizes());
1554 style->setWidth(Length(size.width(), Fixed));
1555 style->setHeight(Length(size.height(), Fixed));
1556 style->setBoxShadow(nullptr);
1559 bool RenderThemeMac::paintSearchFieldResultsDecoration(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1561 Node* input = o->node()->shadowAncestorNode();
1562 if (!input->renderer()->isBox())
1565 LocalCurrentGraphicsContext localContext(paintInfo.context);
1566 setSearchCellState(input->renderer(), r);
1568 NSSearchFieldCell* search = this->search();
1570 if ([search searchMenuTemplate] != nil)
1571 [search setSearchMenuTemplate:nil];
1573 updateActiveState([search searchButtonCell], o);
1575 FloatRect localBounds = [search searchButtonRectForBounds:NSRect(input->renderBox()->borderBoxRect())];
1576 localBounds = convertToPaintingRect(input->renderer(), o, localBounds, r);
1578 [[search searchButtonCell] drawWithFrame:localBounds inView:documentViewFor(o)];
1579 [[search searchButtonCell] setControlView:nil];
1583 const int resultsArrowWidth = 5;
1584 void RenderThemeMac::adjustSearchFieldResultsButtonStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
1586 IntSize size = sizeForSystemFont(style, resultsButtonSizes());
1587 style->setWidth(Length(size.width() + resultsArrowWidth, Fixed));
1588 style->setHeight(Length(size.height(), Fixed));
1589 style->setBoxShadow(nullptr);
1592 bool RenderThemeMac::paintSearchFieldResultsButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1594 Node* input = o->node()->shadowAncestorNode();
1595 if (!input->renderer()->isBox())
1598 LocalCurrentGraphicsContext localContext(paintInfo.context);
1599 setSearchCellState(input->renderer(), r);
1601 NSSearchFieldCell* search = this->search();
1603 updateActiveState([search searchButtonCell], o);
1605 if (![search searchMenuTemplate])
1606 [search setSearchMenuTemplate:searchMenuTemplate()];
1608 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1609 float zoomLevel = o->style()->effectiveZoom();
1611 FloatRect localBounds = [search searchButtonRectForBounds:NSRect(input->renderBox()->borderBoxRect())];
1612 localBounds = convertToPaintingRect(input->renderer(), o, localBounds, r);
1614 IntRect unzoomedRect(localBounds);
1615 if (zoomLevel != 1.0f) {
1616 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
1617 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
1618 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y());
1619 paintInfo.context->scale(FloatSize(zoomLevel, zoomLevel));
1620 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y());
1623 [[search searchButtonCell] drawWithFrame:unzoomedRect inView:documentViewFor(o)];
1624 [[search searchButtonCell] setControlView:nil];
1631 MediaControllerThemeClassic = 1,
1632 MediaControllerThemeQuickTime = 2
1633 } MediaControllerThemeStyle;
1635 static int mediaControllerTheme()
1637 static int controllerTheme = -1;
1639 if (controllerTheme != -1)
1640 return controllerTheme;
1642 controllerTheme = MediaControllerThemeClassic;
1645 Boolean useQTMediaUIPref = CFPreferencesGetAppBooleanValue(CFSTR("UseQuickTimeMediaUI"), CFSTR("com.apple.WebCore"), &validKey);
1647 if (validKey && !useQTMediaUIPref)
1648 return controllerTheme;
1650 controllerTheme = MediaControllerThemeQuickTime;
1651 return controllerTheme;
1655 const int sliderThumbWidth = 15;
1656 const int sliderThumbHeight = 15;
1657 const int mediaSliderThumbWidth = 13;
1658 const int mediaSliderThumbHeight = 14;
1660 void RenderThemeMac::adjustSliderThumbSize(RenderStyle* style) const
1662 float zoomLevel = style->effectiveZoom();
1663 if (style->appearance() == SliderThumbHorizontalPart || style->appearance() == SliderThumbVerticalPart) {
1664 style->setWidth(Length(static_cast<int>(sliderThumbWidth * zoomLevel), Fixed));
1665 style->setHeight(Length(static_cast<int>(sliderThumbHeight * zoomLevel), Fixed));
1669 adjustMediaSliderThumbSize(style);
1675 void RenderThemeMac::adjustMediaSliderThumbSize(RenderStyle* style) const
1677 ControlPart part = style->appearance();
1679 if (part == MediaSliderThumbPart || part == MediaVolumeSliderThumbPart) {
1680 int width = mediaSliderThumbWidth;
1681 int height = mediaSliderThumbHeight;
1683 if (mediaControllerTheme() == MediaControllerThemeQuickTime) {
1686 wkMeasureMediaUIPart(part == MediaSliderThumbPart ? MediaSliderThumb : MediaVolumeSliderThumb, MediaControllerThemeQuickTime, NULL, &size);
1688 height = size.height;
1691 float zoomLevel = style->effectiveZoom();
1692 style->setWidth(Length(static_cast<int>(width * zoomLevel), Fixed));
1693 style->setHeight(Length(static_cast<int>(height * zoomLevel), Fixed));
1697 enum WKMediaControllerThemeState {
1698 MediaUIPartDisabledFlag = 1 << 0,
1699 MediaUIPartPressedFlag = 1 << 1,
1700 MediaUIPartDrawEndCapsFlag = 1 << 3,
1703 static unsigned getMediaUIPartStateFlags(Node* node)
1707 if (node->disabled())
1708 flags |= MediaUIPartDisabledFlag;
1709 else if (node->active())
1710 flags |= MediaUIPartPressedFlag;
1714 // Utility to scale when the UI part are not scaled by wkDrawMediaUIPart
1715 static FloatRect getUnzoomedRectAndAdjustCurrentContext(RenderObject* o, const PaintInfo& paintInfo, const IntRect &originalRect)
1717 float zoomLevel = o->style()->effectiveZoom();
1718 FloatRect unzoomedRect(originalRect);
1719 if (zoomLevel != 1.0f && mediaControllerTheme() == MediaControllerThemeQuickTime) {
1720 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
1721 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
1722 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y());
1723 paintInfo.context->scale(FloatSize(zoomLevel, zoomLevel));
1724 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y());
1726 return unzoomedRect;
1730 bool RenderThemeMac::paintMediaFullscreenButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1732 Node* node = o->node();
1736 LocalCurrentGraphicsContext localContext(paintInfo.context);
1737 wkDrawMediaUIPart(MediaFullscreenButton, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
1741 bool RenderThemeMac::paintMediaMuteButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1743 Node* node = o->node();
1744 Node* mediaNode = node ? node->shadowAncestorNode() : 0;
1745 if (!mediaNode || (!mediaNode->hasTagName(videoTag) && !mediaNode->hasTagName(audioTag)))
1748 if (MediaControlMuteButtonElement* btn = static_cast<MediaControlMuteButtonElement*>(node)) {
1749 LocalCurrentGraphicsContext localContext(paintInfo.context);
1750 wkDrawMediaUIPart(btn->displayType(), mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
1756 bool RenderThemeMac::paintMediaPlayButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1758 Node* node = o->node();
1759 Node* mediaNode = node ? node->shadowAncestorNode() : 0;
1760 if (!mediaNode || (!mediaNode->hasTagName(videoTag) && !mediaNode->hasTagName(audioTag)))
1763 if (MediaControlPlayButtonElement* btn = static_cast<MediaControlPlayButtonElement*>(node)) {
1764 LocalCurrentGraphicsContext localContext(paintInfo.context);
1765 wkDrawMediaUIPart(btn->displayType(), mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
1770 bool RenderThemeMac::paintMediaSeekBackButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1772 Node* node = o->node();
1776 LocalCurrentGraphicsContext localContext(paintInfo.context);
1777 wkDrawMediaUIPart(MediaSeekBackButton, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
1781 bool RenderThemeMac::paintMediaSeekForwardButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1783 Node* node = o->node();
1787 LocalCurrentGraphicsContext localContext(paintInfo.context);
1788 wkDrawMediaUIPart(MediaSeekForwardButton, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
1792 bool RenderThemeMac::paintMediaSliderTrack(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1794 Node* node = o->node();
1795 Node* mediaNode = node ? node->shadowAncestorNode() : 0;
1796 if (!mediaNode || !mediaNode->isElementNode() || !static_cast<Element*>(mediaNode)->isMediaElement())
1799 HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(mediaNode);
1803 RefPtr<TimeRanges> timeRanges = mediaElement->buffered();
1804 ExceptionCode ignoredException;
1805 float timeLoaded = timeRanges->length() ? timeRanges->end(0, ignoredException) : 0;
1806 float currentTime = mediaElement->currentTime();
1807 float duration = mediaElement->duration();
1808 if (isnan(duration))
1811 ContextContainer cgContextContainer(paintInfo.context);
1812 CGContextRef context = cgContextContainer.context();
1813 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1814 FloatRect unzoomedRect = getUnzoomedRectAndAdjustCurrentContext(o, paintInfo, r);
1815 wkDrawMediaSliderTrack(mediaControllerTheme(), context, unzoomedRect,
1816 timeLoaded, currentTime, duration, getMediaUIPartStateFlags(node));
1820 bool RenderThemeMac::paintMediaSliderThumb(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1822 Node* node = o->node();
1826 LocalCurrentGraphicsContext localContext(paintInfo.context);
1827 wkDrawMediaUIPart(MediaSliderThumb, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
1831 bool RenderThemeMac::paintMediaRewindButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1833 Node* node = o->node();
1837 LocalCurrentGraphicsContext localContext(paintInfo.context);
1838 wkDrawMediaUIPart(MediaRewindButton, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
1842 bool RenderThemeMac::paintMediaReturnToRealtimeButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1844 Node* node = o->node();
1848 LocalCurrentGraphicsContext localContext(paintInfo.context);
1849 wkDrawMediaUIPart(MediaReturnToRealtimeButton, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
1853 bool RenderThemeMac::paintMediaToggleClosedCaptionsButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1855 HTMLInputElement* node = static_cast<HTMLInputElement*>(o->node());
1859 MediaControlToggleClosedCaptionsButtonElement* btn = static_cast<MediaControlToggleClosedCaptionsButtonElement*>(node);
1863 LocalCurrentGraphicsContext localContext(paintInfo.context);
1864 wkDrawMediaUIPart(btn->displayType(), mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
1869 bool RenderThemeMac::paintMediaControlsBackground(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1871 Node* node = o->node();
1875 LocalCurrentGraphicsContext localContext(paintInfo.context);
1876 wkDrawMediaUIPart(MediaTimelineContainer, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
1880 bool RenderThemeMac::paintMediaCurrentTime(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1882 Node* node = o->node();
1886 ContextContainer cgContextContainer(paintInfo.context);
1887 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1888 FloatRect unzoomedRect = getUnzoomedRectAndAdjustCurrentContext(o, paintInfo, r);
1889 wkDrawMediaUIPart(MediaCurrentTimeDisplay, mediaControllerTheme(), cgContextContainer.context(), unzoomedRect, getMediaUIPartStateFlags(node));
1893 bool RenderThemeMac::paintMediaTimeRemaining(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1895 Node* node = o->node();
1899 ContextContainer cgContextContainer(paintInfo.context);
1900 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1901 FloatRect unzoomedRect = getUnzoomedRectAndAdjustCurrentContext(o, paintInfo, r);
1902 wkDrawMediaUIPart(MediaTimeRemainingDisplay, mediaControllerTheme(), cgContextContainer.context(), unzoomedRect, getMediaUIPartStateFlags(node));
1906 bool RenderThemeMac::paintMediaVolumeSliderContainer(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1908 Node* node = o->node();
1912 LocalCurrentGraphicsContext localContext(paintInfo.context);
1913 wkDrawMediaUIPart(MediaVolumeSliderContainer, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
1917 bool RenderThemeMac::paintMediaVolumeSliderTrack(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1919 Node* node = o->node();
1923 LocalCurrentGraphicsContext localContext(paintInfo.context);
1924 wkDrawMediaUIPart(MediaVolumeSlider, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
1928 bool RenderThemeMac::paintMediaVolumeSliderThumb(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1930 Node* node = o->node();
1934 LocalCurrentGraphicsContext localContext(paintInfo.context);
1935 wkDrawMediaUIPart(MediaVolumeSliderThumb, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
1939 String RenderThemeMac::extraMediaControlsStyleSheet()
1942 if (mediaControllerTheme() == MediaControllerThemeQuickTime)
1943 return String(mediaControlsQuickTimeUserAgentStyleSheet, sizeof(mediaControlsQuickTimeUserAgentStyleSheet));
1947 ASSERT_NOT_REACHED();
1952 #if ENABLE(FULLSCREEN_API)
1953 String RenderThemeMac::extraFullScreenStyleSheet()
1956 if (mediaControllerTheme() == MediaControllerThemeQuickTime)
1957 return String(fullscreenQuickTimeUserAgentStyleSheet, sizeof(fullscreenQuickTimeUserAgentStyleSheet));
1961 ASSERT_NOT_REACHED();
1967 bool RenderThemeMac::hasOwnDisabledStateHandlingFor(ControlPart part) const
1969 if (part == MediaMuteButtonPart)
1972 return mediaControllerTheme() == MediaControllerThemeClassic;
1975 bool RenderThemeMac::usesMediaControlStatusDisplay()
1977 return mediaControllerTheme() == MediaControllerThemeQuickTime;
1980 bool RenderThemeMac::usesMediaControlVolumeSlider() const
1982 return mediaControllerTheme() == MediaControllerThemeQuickTime;
1985 IntPoint RenderThemeMac::volumeSliderOffsetFromMuteButton(RenderBox* muteButtonBox, const IntSize& size) const
1987 return RenderMediaControls::volumeSliderOffsetFromMuteButton(muteButtonBox, size);
1990 bool RenderThemeMac::shouldShowPlaceholderWhenFocused() const
1992 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
1999 #endif // ENABLE(VIDEO)
2001 NSPopUpButtonCell* RenderThemeMac::popupButton() const
2003 if (!m_popupButton) {
2004 m_popupButton.adoptNS([[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO]);
2005 [m_popupButton.get() setUsesItemFromMenu:NO];
2006 [m_popupButton.get() setFocusRingType:NSFocusRingTypeExterior];
2009 return m_popupButton.get();
2012 NSSearchFieldCell* RenderThemeMac::search() const
2015 m_search.adoptNS([[NSSearchFieldCell alloc] initTextCell:@""]);
2016 [m_search.get() setBezelStyle:NSTextFieldRoundedBezel];
2017 [m_search.get() setBezeled:YES];
2018 [m_search.get() setEditable:YES];
2019 [m_search.get() setFocusRingType:NSFocusRingTypeExterior];
2022 return m_search.get();
2025 NSMenu* RenderThemeMac::searchMenuTemplate() const
2027 if (!m_searchMenuTemplate)
2028 m_searchMenuTemplate.adoptNS([[NSMenu alloc] initWithTitle:@""]);
2030 return m_searchMenuTemplate.get();
2033 NSSliderCell* RenderThemeMac::sliderThumbHorizontal() const
2035 if (!m_sliderThumbHorizontal) {
2036 m_sliderThumbHorizontal.adoptNS([[NSSliderCell alloc] init]);
2037 [m_sliderThumbHorizontal.get() setTitle:nil];
2038 [m_sliderThumbHorizontal.get() setSliderType:NSLinearSlider];
2039 [m_sliderThumbHorizontal.get() setControlSize:NSSmallControlSize];
2040 [m_sliderThumbHorizontal.get() setFocusRingType:NSFocusRingTypeExterior];
2043 return m_sliderThumbHorizontal.get();
2046 NSSliderCell* RenderThemeMac::sliderThumbVertical() const
2048 if (!m_sliderThumbVertical) {
2049 m_sliderThumbVertical.adoptNS([[NSSliderCell alloc] init]);
2050 [m_sliderThumbVertical.get() setTitle:nil];
2051 [m_sliderThumbVertical.get() setSliderType:NSLinearSlider];
2052 [m_sliderThumbVertical.get() setControlSize:NSSmallControlSize];
2053 [m_sliderThumbVertical.get() setFocusRingType:NSFocusRingTypeExterior];
2056 return m_sliderThumbVertical.get();
2059 String RenderThemeMac::fileListNameForWidth(const Vector<String>& filenames, const Font& font, int width)
2064 String strToTruncate;
2065 if (filenames.isEmpty())
2066 strToTruncate = fileButtonNoFileSelectedLabel();
2067 else if (filenames.size() == 1)
2068 strToTruncate = [[NSFileManager defaultManager] displayNameAtPath:(filenames[0])];
2070 return StringTruncator::rightTruncate(multipleFileUploadText(filenames.size()), width, font, StringTruncator::EnableRoundingHacks);
2072 return StringTruncator::centerTruncate(strToTruncate, width, font, StringTruncator::EnableRoundingHacks);
2075 } // namespace WebCore