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.
23 #import "CalendarPickerMac.h"
24 #import "LayoutTestSupport.h"
25 #import "LocalCurrentGraphicsContext.h"
26 #import "RenderThemeChromiumMac.h"
28 #import "RenderMediaControlsChromium.h"
29 #import "WebCoreSystemInterface.h"
30 #import "UserAgentStyleSheets.h"
31 #import <Carbon/Carbon.h>
32 #import <Cocoa/Cocoa.h>
33 #import <wtf/RetainPtr.h>
34 #import <wtf/StdLibExtras.h>
37 @interface RTCMFlippedView : NSView
41 - (NSText *)currentEditor;
45 @implementation RTCMFlippedView
48 return [[NSGraphicsContext currentContext] isFlipped];
51 - (NSText *)currentEditor {
61 static NSView* view = [[RTCMFlippedView alloc] init];
65 PassRefPtr<RenderTheme> RenderTheme::themeForPage(Page*)
67 static RenderTheme* rt = RenderThemeChromiumMac::create().leakRef();
71 PassRefPtr<RenderTheme> RenderThemeChromiumMac::create()
73 return adoptRef(new RenderThemeChromiumMac);
76 bool RenderThemeChromiumMac::supportsDataListUI(const AtomicString& type) const
78 return RenderThemeChromiumCommon::supportsDataListUI(type);
81 bool RenderThemeChromiumMac::usesTestModeFocusRingColor() const
83 return isRunningLayoutTest();
86 NSView* RenderThemeChromiumMac::documentViewFor(RenderObject*) const
91 const int autofillPopupHorizontalPadding = 4;
93 // These functions are called with MenuListPart or MenulistButtonPart appearance by RenderMenuList, or with TextFieldPart appearance by AutofillPopupMenuClient.
94 // We assume only AutofillPopupMenuClient gives TexfieldPart appearance here.
95 // We want to change only Autofill padding.
96 // In the future, we have to separate Autofill popup window logic from WebKit to Chromium.
97 int RenderThemeChromiumMac::popupInternalPaddingLeft(RenderStyle* style) const
99 if (style->appearance() == TextFieldPart)
100 return autofillPopupHorizontalPadding;
102 return RenderThemeMac::popupInternalPaddingLeft(style);
105 int RenderThemeChromiumMac::popupInternalPaddingRight(RenderStyle* style) const
107 if (style->appearance() == TextFieldPart)
108 return autofillPopupHorizontalPadding;
110 return RenderThemeMac::popupInternalPaddingRight(style);
113 // Updates the control tint (a.k.a. active state) of |cell| (from |o|).
114 // In the Chromium port, the renderer runs as a background process and controls'
115 // NSCell(s) lack a parent NSView. Therefore controls don't have their tint
116 // color updated correctly when the application is activated/deactivated.
117 // FocusController's setActive() is called when the application is
118 // activated/deactivated, which causes a repaint at which time this code is
120 // This function should be called before drawing any NSCell-derived controls,
121 // unless you're sure it isn't needed.
122 void RenderThemeChromiumMac::updateActiveState(NSCell* cell, const RenderObject* o)
124 NSControlTint oldTint = [cell controlTint];
125 NSControlTint tint = isActive(o) ? [NSColor currentControlTint] :
126 static_cast<NSControlTint>(NSClearControlTint);
129 [cell setControlTint:tint];
132 bool RenderThemeChromiumMac::shouldShowPlaceholderWhenFocused() const
137 bool RenderThemeChromiumMac::paintTextField(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
139 // Using the Cocoa code to paint the text field as RenderThemeMac does runs
140 // into a bug when building against the 10.5 SDK, so we are forced here to
141 // use the SPI. This override of paintTextField should be able to be removed
142 // when 10.6 is the minimum required system and Chromium is built against
145 // https://bugs.webkit.org/show_bug.cgi?id=75860
146 // http://code.google.com/p/chromium/issues/detail?id=109567
148 LocalCurrentGraphicsContext localContext(paintInfo.context);
149 wkDrawBezeledTextFieldCell(r, isEnabled(o) && !isReadOnlyControl(o));
156 void RenderThemeChromiumMac::adjustMediaSliderThumbSize(RenderStyle* style) const
158 RenderMediaControlsChromium::adjustMediaSliderThumbSize(style);
161 bool RenderThemeChromiumMac::paintMediaPlayButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
163 return RenderMediaControlsChromium::paintMediaControlsPart(MediaPlayButton, object, paintInfo, rect);
166 bool RenderThemeChromiumMac::paintMediaMuteButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
168 return RenderMediaControlsChromium::paintMediaControlsPart(MediaMuteButton, object, paintInfo, rect);
171 bool RenderThemeChromiumMac::paintMediaSliderTrack(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
173 return RenderMediaControlsChromium::paintMediaControlsPart(MediaSlider, object, paintInfo, rect);
176 String RenderThemeChromiumMac::extraMediaControlsStyleSheet()
178 return String(mediaControlsChromiumUserAgentStyleSheet, sizeof(mediaControlsChromiumUserAgentStyleSheet));
181 #if ENABLE(FULLSCREEN_API)
182 String RenderThemeChromiumMac::extraFullScreenStyleSheet()
184 // FIXME: Chromium may wish to style its default media controls differently in fullscreen.
189 String RenderThemeChromiumMac::extraDefaultStyleSheet()
191 return RenderThemeMac::extraDefaultStyleSheet() +
192 String(themeChromiumUserAgentStyleSheet, sizeof(themeChromiumUserAgentStyleSheet));
195 #if ENABLE(CALENDAR_PICKER)
196 CString RenderThemeChromiumMac::extraCalendarPickerStyleSheet()
198 return CString(calendarPickerMacCss, WTF_ARRAY_LENGTH(calendarPickerMacCss));
202 bool RenderThemeChromiumMac::paintMediaVolumeSliderContainer(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
207 bool RenderThemeChromiumMac::paintMediaVolumeSliderTrack(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
209 return RenderMediaControlsChromium::paintMediaControlsPart(MediaVolumeSlider, object, paintInfo, rect);
212 bool RenderThemeChromiumMac::paintMediaVolumeSliderThumb(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
214 return RenderMediaControlsChromium::paintMediaControlsPart(MediaVolumeSliderThumb, object, paintInfo, rect);
217 bool RenderThemeChromiumMac::paintMediaSliderThumb(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
219 return RenderMediaControlsChromium::paintMediaControlsPart(MediaSliderThumb, object, paintInfo, rect);
222 IntPoint RenderThemeChromiumMac::volumeSliderOffsetFromMuteButton(RenderBox* muteButtonBox, const IntSize& size) const
224 return RenderTheme::volumeSliderOffsetFromMuteButton(muteButtonBox, size);
227 String RenderThemeChromiumMac::formatMediaControlsTime(float time) const
229 return RenderMediaControlsChromium::formatMediaControlsTime(time);
232 String RenderThemeChromiumMac::formatMediaControlsCurrentTime(float currentTime, float duration) const
234 return RenderMediaControlsChromium::formatMediaControlsCurrentTime(currentTime, duration);
237 String RenderThemeChromiumMac::formatMediaControlsRemainingTime(float currentTime, float duration) const
239 return RenderThemeChromiumMac::formatMediaControlsRemainingTime(currentTime, duration);
242 bool RenderThemeChromiumMac::paintMediaFullscreenButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
244 return RenderMediaControlsChromium::paintMediaControlsPart(MediaEnterFullscreenButton, object, paintInfo, rect);
248 } // namespace WebCore