Fix the issue that Web Audio test case fails on PR3.
[framework/web/webkit-efl.git] / Source / WebCore / rendering / RenderThemeChromiumMac.mm
1 /*
2  * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3  * Copyright (C) 2008, 2009 Google, Inc.
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 #import "config.h"
22
23 #import "CalendarPickerMac.h"
24 #import "LayoutTestSupport.h"
25 #import "LocalCurrentGraphicsContext.h"
26 #import "RenderThemeChromiumMac.h"
27 #import "PaintInfo.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>
35 #import <math.h>
36
37 @interface RTCMFlippedView : NSView
38 {}
39
40 - (BOOL)isFlipped;
41 - (NSText *)currentEditor;
42
43 @end
44
45 @implementation RTCMFlippedView
46
47 - (BOOL)isFlipped {
48     return [[NSGraphicsContext currentContext] isFlipped];
49 }
50
51 - (NSText *)currentEditor {
52     return nil;
53 }
54
55 @end
56
57 namespace WebCore {
58
59 NSView* FlippedView()
60 {
61     static NSView* view = [[RTCMFlippedView alloc] init];
62     return view;
63 }
64
65 PassRefPtr<RenderTheme> RenderTheme::themeForPage(Page*)
66 {
67     static RenderTheme* rt = RenderThemeChromiumMac::create().leakRef();
68     return rt;
69 }
70
71 PassRefPtr<RenderTheme> RenderThemeChromiumMac::create()
72 {
73     return adoptRef(new RenderThemeChromiumMac);
74 }
75
76 bool RenderThemeChromiumMac::supportsDataListUI(const AtomicString& type) const
77 {
78     return RenderThemeChromiumCommon::supportsDataListUI(type);
79 }
80
81 bool RenderThemeChromiumMac::usesTestModeFocusRingColor() const
82 {
83     return isRunningLayoutTest();
84 }
85
86 NSView* RenderThemeChromiumMac::documentViewFor(RenderObject*) const
87 {
88     return FlippedView();
89 }
90
91 const int autofillPopupHorizontalPadding = 4;
92
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
98 {
99     if (style->appearance() == TextFieldPart)
100         return autofillPopupHorizontalPadding;
101
102     return RenderThemeMac::popupInternalPaddingLeft(style);
103 }
104
105 int RenderThemeChromiumMac::popupInternalPaddingRight(RenderStyle* style) const
106 {
107     if (style->appearance() == TextFieldPart)
108         return autofillPopupHorizontalPadding;
109
110     return RenderThemeMac::popupInternalPaddingRight(style);
111 }
112
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
119 // called.
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)
123 {
124     NSControlTint oldTint = [cell controlTint];
125     NSControlTint tint = isActive(o) ? [NSColor currentControlTint] :
126                                        static_cast<NSControlTint>(NSClearControlTint);
127
128     if (tint != oldTint)
129         [cell setControlTint:tint];
130 }
131
132 bool RenderThemeChromiumMac::shouldShowPlaceholderWhenFocused() const
133 {
134     return true;
135 }
136
137 bool RenderThemeChromiumMac::paintTextField(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
138 {
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
143     // the 10.6 SDK.
144     //
145     // https://bugs.webkit.org/show_bug.cgi?id=75860
146     // http://code.google.com/p/chromium/issues/detail?id=109567
147
148     LocalCurrentGraphicsContext localContext(paintInfo.context);
149     wkDrawBezeledTextFieldCell(r, isEnabled(o) && !isReadOnlyControl(o));
150
151     return false;
152 }
153
154 #if ENABLE(VIDEO)
155
156 void RenderThemeChromiumMac::adjustMediaSliderThumbSize(RenderStyle* style) const
157 {
158     RenderMediaControlsChromium::adjustMediaSliderThumbSize(style);
159 }
160
161 bool RenderThemeChromiumMac::paintMediaPlayButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
162 {
163     return RenderMediaControlsChromium::paintMediaControlsPart(MediaPlayButton, object, paintInfo, rect);
164 }
165
166 bool RenderThemeChromiumMac::paintMediaMuteButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
167 {
168     return RenderMediaControlsChromium::paintMediaControlsPart(MediaMuteButton, object, paintInfo, rect);
169 }
170
171 bool RenderThemeChromiumMac::paintMediaSliderTrack(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
172 {
173     return RenderMediaControlsChromium::paintMediaControlsPart(MediaSlider, object, paintInfo, rect);
174 }
175
176 String RenderThemeChromiumMac::extraMediaControlsStyleSheet()
177 {
178     return String(mediaControlsChromiumUserAgentStyleSheet, sizeof(mediaControlsChromiumUserAgentStyleSheet));
179 }
180
181 #if ENABLE(FULLSCREEN_API)
182 String RenderThemeChromiumMac::extraFullScreenStyleSheet()
183 {
184     // FIXME: Chromium may wish to style its default media controls differently in fullscreen.
185     return String();
186 }
187 #endif
188
189 String RenderThemeChromiumMac::extraDefaultStyleSheet()
190 {
191     return RenderThemeMac::extraDefaultStyleSheet() +
192            String(themeChromiumUserAgentStyleSheet, sizeof(themeChromiumUserAgentStyleSheet));
193 }
194
195 #if ENABLE(CALENDAR_PICKER)
196 CString RenderThemeChromiumMac::extraCalendarPickerStyleSheet()
197 {
198     return CString(calendarPickerMacCss, WTF_ARRAY_LENGTH(calendarPickerMacCss));
199 }
200 #endif
201
202 bool RenderThemeChromiumMac::paintMediaVolumeSliderContainer(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
203 {
204     return true;
205 }
206
207 bool RenderThemeChromiumMac::paintMediaVolumeSliderTrack(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
208 {
209     return RenderMediaControlsChromium::paintMediaControlsPart(MediaVolumeSlider, object, paintInfo, rect);
210 }
211
212 bool RenderThemeChromiumMac::paintMediaVolumeSliderThumb(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
213 {
214     return RenderMediaControlsChromium::paintMediaControlsPart(MediaVolumeSliderThumb, object, paintInfo, rect);
215 }
216
217 bool RenderThemeChromiumMac::paintMediaSliderThumb(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
218 {
219     return RenderMediaControlsChromium::paintMediaControlsPart(MediaSliderThumb, object, paintInfo, rect);
220 }
221
222 IntPoint RenderThemeChromiumMac::volumeSliderOffsetFromMuteButton(RenderBox* muteButtonBox, const IntSize& size) const
223 {
224     return RenderTheme::volumeSliderOffsetFromMuteButton(muteButtonBox, size);
225 }
226
227 String RenderThemeChromiumMac::formatMediaControlsTime(float time) const
228 {
229     return RenderMediaControlsChromium::formatMediaControlsTime(time);
230 }
231
232 String RenderThemeChromiumMac::formatMediaControlsCurrentTime(float currentTime, float duration) const
233 {
234     return RenderMediaControlsChromium::formatMediaControlsCurrentTime(currentTime, duration);
235 }
236
237 String RenderThemeChromiumMac::formatMediaControlsRemainingTime(float currentTime, float duration) const
238 {
239     return RenderThemeChromiumMac::formatMediaControlsRemainingTime(currentTime, duration);
240 }
241
242 bool RenderThemeChromiumMac::paintMediaFullscreenButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
243 {
244     return RenderMediaControlsChromium::paintMediaControlsPart(MediaEnterFullscreenButton, object, paintInfo, rect);
245 }
246 #endif
247
248 } // namespace WebCore