2 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Google, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #import "RenderThemeChromiumMac.h"
24 #import "PlatformSupport.h"
25 #import "RenderMediaControlsChromium.h"
26 #import "UserAgentStyleSheets.h"
27 #import <Carbon/Carbon.h>
28 #import <Cocoa/Cocoa.h>
29 #import <wtf/RetainPtr.h>
30 #import <wtf/StdLibExtras.h>
33 @interface RTCMFlippedView : NSView
37 - (NSText *)currentEditor;
41 @implementation RTCMFlippedView
44 return [[NSGraphicsContext currentContext] isFlipped];
47 - (NSText *)currentEditor {
57 static NSView* view = [[RTCMFlippedView alloc] init];
61 PassRefPtr<RenderTheme> RenderTheme::themeForPage(Page*)
63 static RenderTheme* rt = RenderThemeChromiumMac::create().releaseRef();
67 PassRefPtr<RenderTheme> RenderThemeChromiumMac::create()
69 return adoptRef(new RenderThemeChromiumMac);
72 bool RenderThemeChromiumMac::usesTestModeFocusRingColor() const
74 return PlatformSupport::layoutTestMode();
77 NSView* RenderThemeChromiumMac::documentViewFor(RenderObject*) const
82 const int autofillPopupHorizontalPadding = 4;
84 // These functions are called with MenuListPart or MenulistButtonPart appearance by RenderMenuList, or with TextFieldPart appearance by AutofillPopupMenuClient.
85 // We assume only AutofillPopupMenuClient gives TexfieldPart appearance here.
86 // We want to change only Autofill padding.
87 // In the future, we have to separate Autofill popup window logic from WebKit to Chromium.
88 int RenderThemeChromiumMac::popupInternalPaddingLeft(RenderStyle* style) const
90 if (style->appearance() == TextFieldPart)
91 return autofillPopupHorizontalPadding;
93 return RenderThemeMac::popupInternalPaddingLeft(style);
96 int RenderThemeChromiumMac::popupInternalPaddingRight(RenderStyle* style) const
98 if (style->appearance() == TextFieldPart)
99 return autofillPopupHorizontalPadding;
101 return RenderThemeMac::popupInternalPaddingRight(style);
104 // Updates the control tint (a.k.a. active state) of |cell| (from |o|).
105 // In the Chromium port, the renderer runs as a background process and controls'
106 // NSCell(s) lack a parent NSView. Therefore controls don't have their tint
107 // color updated correctly when the application is activated/deactivated.
108 // FocusController's setActive() is called when the application is
109 // activated/deactivated, which causes a repaint at which time this code is
111 // This function should be called before drawing any NSCell-derived controls,
112 // unless you're sure it isn't needed.
113 void RenderThemeChromiumMac::updateActiveState(NSCell* cell, const RenderObject* o)
115 NSControlTint oldTint = [cell controlTint];
116 NSControlTint tint = isActive(o) ? [NSColor currentControlTint] :
117 static_cast<NSControlTint>(NSClearControlTint);
120 [cell setControlTint:tint];
125 void RenderThemeChromiumMac::adjustMediaSliderThumbSize(RenderStyle* style) const
127 RenderMediaControlsChromium::adjustMediaSliderThumbSize(style);
130 bool RenderThemeChromiumMac::paintMediaPlayButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
132 return RenderMediaControlsChromium::paintMediaControlsPart(MediaPlayButton, object, paintInfo, rect);
135 bool RenderThemeChromiumMac::paintMediaMuteButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
137 return RenderMediaControlsChromium::paintMediaControlsPart(MediaMuteButton, object, paintInfo, rect);
140 bool RenderThemeChromiumMac::paintMediaSliderTrack(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
142 return RenderMediaControlsChromium::paintMediaControlsPart(MediaSlider, object, paintInfo, rect);
145 bool RenderThemeChromiumMac::paintMediaControlsBackground(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
147 return RenderMediaControlsChromium::paintMediaControlsPart(MediaTimelineContainer, object, paintInfo, rect);
150 String RenderThemeChromiumMac::extraMediaControlsStyleSheet()
152 return String(mediaControlsChromiumUserAgentStyleSheet, sizeof(mediaControlsChromiumUserAgentStyleSheet));
155 #if ENABLE(FULLSCREEN_API)
156 String RenderThemeChromiumMac::extraFullScreenStyleSheet()
158 // FIXME: Chromium may wish to style its default media controls differently in fullscreen.
163 String RenderThemeChromiumMac::extraDefaultStyleSheet()
165 return RenderThemeMac::extraDefaultStyleSheet() +
166 String(themeChromiumUserAgentStyleSheet, sizeof(themeChromiumUserAgentStyleSheet));
170 bool RenderThemeChromiumMac::paintMediaVolumeSliderContainer(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
175 bool RenderThemeChromiumMac::paintMediaVolumeSliderTrack(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
177 return RenderMediaControlsChromium::paintMediaControlsPart(MediaVolumeSlider, object, paintInfo, rect);
180 bool RenderThemeChromiumMac::paintMediaVolumeSliderThumb(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
182 return RenderMediaControlsChromium::paintMediaControlsPart(MediaVolumeSliderThumb, object, paintInfo, rect);
185 bool RenderThemeChromiumMac::paintMediaSliderThumb(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
187 return RenderMediaControlsChromium::paintMediaControlsPart(MediaSliderThumb, object, paintInfo, rect);
190 IntPoint RenderThemeChromiumMac::volumeSliderOffsetFromMuteButton(RenderBox* muteButtonBox, const IntSize& size) const
192 return RenderTheme::volumeSliderOffsetFromMuteButton(muteButtonBox, size);
196 } // namespace WebCore